Hi @KURAMOTOAHUJATAIRA-3118 Thank you so much for sharing the solution identified by the Azure team. I am sharing the solution below for easier access on the Community thread. Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .
Error Message:
2024-01-29T08:40:08Z [Error] 2024-01-29T08:40:08+00:00 [ERROR] getIothubSakey test 500 ArgumentError: authentication is invalid.
Issue:
Attempting to update a device's state from disabled to enabled using the IoTHub SDK's Registry.fromConnectionString
results in an error
Solution:
Azure team confirmed that the issue occurs with IoT Hub resources that have undergone the "Gateway Infrastructure Upgrade" mentioned in the following update announcement:
Reference: General availability: IoT Hub Service Upgrade https://azure.microsoft.com/en-us/updates/general-availability-iot-hub-service-upgrade/
In the Device class used in the code, it was found that there were values containing properties SymmetricKey
and symmetricKey
, which could be considered duplicates, in the authentication section. It was noted that if the operation proceeded with this definition as is, errors would be returned due to stricter validation of API request content in IoT Hub resources that have undergone the upgrade process.
Reference: Authentication interface https://learn.microsoft.com/en-us/javascript/api/azure-iothub/device.authentication?view=azure-node-latest
As a solution to this issue, it was suggested to handle the update method using an object excluding only the inappropriate SymmetricKey
field. The code example is as follows:
If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.
async function updateDevice(deviceId) {
const registryReadWriteRegistry = iothub.Registry.fromConnectionString(
systemConfig.iothub.registryReadWriteConnectionStr,
);
const deviceInfo = await registryReadWriteRegistry.get(deviceId);
deviceInfo.responseBody.status = 'enabled';
const {responseBody: {authentication: {SymmetricKey, ...rest}, ...outerRest}} = deviceInfo;
const newDeviceInfo = {
...outerRest,
authentication: {...rest}
};
await registryReadWriteRegistry.update(newDeviceInfo);
}
I hope this helps!
If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.