UNPKG

@azure-rest/iot-device-update

Version:

Device Update for IoT Hub is an Azure service that enables customers to publish update for their IoT devices to the cloud, and then deploy that update to their devices (approve updates to groups of devices managed and provisioned in IoT Hub). It leverages

120 lines (75 loc) 4.94 kB
# Azure Device Update for IoT Hub Rest Client library for JavaScript The library provides access to the Device Update for IoT Hub service that enables customers to publish updates for their IoT devices to the cloud, and then deploy these updates to their devices (approve updates to groups of devices managed and provisioned in IoT Hub). **Please rely heavily on the [service's documentation][device_update_product_documentation] and our [REST client docs][rest_client] to use this library** Key links: - [Source code][source_code] - [Package (NPM)][npm] - [API reference documentation][ref_docs] - [Product documentation][device_update_product_documentation] ## Getting started ### Currently supported environments - [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule) ### Prerequisites - Microsoft Azure Subscription: To call Microsoft Azure services, you need to create an [Azure subscription][azure_subscription] - Device Update for IoT Hub instance - Azure IoT Hub instance ### Install the `@azure-rest/iot-device-update` package Install the Azure Iot Device Update client library for JavaScript with `npm`: ```bash npm install @azure-rest/iot-device-update ``` ### Create and authenticate a `DeviceUpdate` To use an [Azure Active Directory (AAD) token credential][authenticate_with_token], provide an instance of the desired credential type obtained from the [@azure/identity][azure_identity_credentials] library. To authenticate with AAD, you must first `npm` install [`@azure/identity`][azure_identity_npm]. After installation, you can choose which type of [credential][azure_identity_credentials] from `@azure/identity` to use. As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client: Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET Use the returned token credential to authenticate the client: ```ts snippet:ReadmeSampleCreateClient_Node import DeviceUpdate from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; const endpoint = "https://<my-instance-id>.api.adu.microsoft.com"; const client = DeviceUpdate(endpoint, new DefaultAzureCredential()); ``` ## Key concepts ### REST Client This client is one of our REST clients. We highly recommend you read how to use a REST client [here][rest_client]. ## Examples The following section shows you how to initialize and authenticate your client, then get all devices. - [Get All Devices](#get-all-devices "Get All Devices") ```ts snippet:ReadmeSampleGetAllDevices import DeviceUpdate from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; const endpoint = "https://<my-instance-id>.api.adu.microsoft.com"; const client = DeviceUpdate(endpoint, new DefaultAzureCredential()); const instanceId = "<my-instance-id>"; const result = await client.path("/deviceupdate/{instanceId}/management/devices", instanceId).get(); console.log(result); ``` ## Troubleshooting ### Logging Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: ```ts snippet:SetLogLevel import { setLogLevel } from "@azure/logger"; setLogLevel("info"); ``` For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). ## Next steps ## Contributing If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code. ## Related projects - [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js) [device_update_product_documentation]: https://learn.microsoft.com/azure/iot-hub-device-update/ [rest_client]: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md [source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/deviceupdate/iot-device-update-rest [npm]: https://www.npmjs.com/org/azure-rest [ref_docs]: https://azure.github.io/azure-sdk-for-js [azure_subscription]: https://azure.microsoft.com/free/ [authenticate_with_token]: https://learn.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token [azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials [azure_identity_npm]: https://www.npmjs.com/package/@azure/identity [default_azure_credential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential