Here’s a comprehensive solution addressing all three focus areas:
Bulk Import Validation:
The root cause is that bulk import doesn’t validate device ID uniqueness across all registry states before creating entries. When imports fail partway through, some devices end up in limbo states that block future enrollments but don’t appear in normal queries.
To clean up existing phantom entries:
// Query all non-active device states
let states = ["PENDING", "INITIALIZING", "FAILED", "DELETED"];
states.forEach(status => {
let devices = Things.DeviceRegistry.GetDevicesByStatus({status: status});
// Review and delete orphaned entries
});
Run this cleanup script to find all problematic entries. Review each device’s creation timestamp - anything from your bulk import period that never reached ACTIVE status should be deleted.
Device ID Uniqueness Enforcement:
ThingWorx 9.5 enforces device ID uniqueness across ALL registry states, including soft-deleted and failed entries. This is stricter than previous versions. The registry maintains historical records for audit purposes, which is why your deleted devices still block new enrollments.
To properly remove a device and free its ID for reuse:
Things.DeviceRegistry.DeleteDevice({deviceId: "DEV-2024-0501", permanent: true});
The permanent: true flag completely removes the device from the registry, including audit history. Without it, the device is soft-deleted and the ID remains blocked.
REST API Pre-Check:
Implement a validation step before enrollment using the REST API:
// Pre-enrollment validation function
function validateDeviceId(deviceId) {
let exists = Things.DeviceRegistry.CheckDeviceExists({deviceId: deviceId, includeDeleted: true});
return !exists;
}
Integrate this into your enrollment workflow. Before calling the enrollment service, verify the device ID is truly available. This prevents enrollment failures and provides immediate feedback.
For bulk imports, create a pre-validation service that processes your import file:
- Read all device IDs from the import file
- Query registry for each ID with includeDeleted=true
- Generate a report of conflicts before starting the import
- Only proceed with import if all IDs are available
This approach catches duplicates before they cause failed enrollments. You can also extend it to check for ID format compliance, valid device types, and other business rules.
Immediate Fix for Your 200 New Devices:
Run the cleanup script above to purge all orphaned entries from your previous bulk import. Then implement the REST API pre-check validation before enrolling your new devices. This two-step approach will resolve your current blockage and prevent future occurrences.
For long-term stability, consider implementing a device ID generation service that guarantees uniqueness by querying the registry before assigning IDs, rather than relying on external ID schemes that might conflict with existing entries.