{"id":17172,"library":"azure-iot-provisioning-device-http","title":"Azure IoT Device Provisioning Service HTTP Transport","description":"The `azure-iot-provisioning-device-http` package provides the HTTP transport layer for interacting with the Azure IoT Hub Device Provisioning Service (DPS) in Node.js applications. It is a crucial component for devices that need to register with DPS using the HTTP protocol, supporting both X.509 certificate and Trusted Platform Module (TPM) authentication methods. As of its latest release, `1.9.2`, this package is part of the broader Azure IoT SDK for Node.js, which typically sees new releases quarterly or bi-annually, bundling updates across various related packages. This transport package is designed to be used in conjunction with the `azure-iot-provisioning-device` client package and a security client package (e.g., `azure-iot-security-x509` or `azure-iot-security-tpm`) to form a complete device provisioning solution, offering a flexible choice of underlying communication protocols.","status":"active","version":"1.9.1","language":"javascript","source_language":"en","source_url":"https://github.com/Azure/azure-iot-sdk-node","tags":["javascript","typescript"],"install":[{"cmd":"npm install azure-iot-provisioning-device-http","lang":"bash","label":"npm"},{"cmd":"yarn add azure-iot-provisioning-device-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add azure-iot-provisioning-device-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required client package to interact with the Device Provisioning Service.","package":"azure-iot-provisioning-device","optional":false},{"reason":"Needed for X.509 certificate-based device authentication.","package":"azure-iot-security-x509","optional":true},{"reason":"Needed for TPM-based device authentication. Note: TPM is supported with HTTP and AMQP transports.","package":"azure-iot-security-tpm","optional":true}],"imports":[{"note":"While CommonJS `require` might still work, modern TypeScript/Node.js projects should prefer ESM `import`.","wrong":"const Http = require('azure-iot-provisioning-device-http');","symbol":"Http","correct":"import { Http } from 'azure-iot-provisioning-device-http';"},{"note":"The primary client class is a named export from the core provisioning package, not a default export.","wrong":"import ProvisioningDeviceClient from 'azure-iot-provisioning-device';","symbol":"ProvisioningDeviceClient","correct":"import { ProvisioningDeviceClient } from 'azure-iot-provisioning-device';"},{"note":"The security client for X.509 authentication is a separate named export.","wrong":"const X509Security = require('azure-iot-security-x509');","symbol":"X509Security","correct":"import { X509Security } from 'azure-iot-security-x509';"}],"quickstart":{"code":"import { ProvisioningDeviceClient } from 'azure-iot-provisioning-device';\nimport { Http } from 'azure-iot-provisioning-device-http';\nimport { X509Security } from 'azure-iot-security-x509';\nimport { readFileSync } from 'fs';\n\n// Replace with your DPS ID Scope and device certificate paths\nconst idScope = process.env.IOTHUB_DPS_ID_SCOPE ?? '';\nconst registrationId = process.env.IOTHUB_DPS_REGISTRATION_ID ?? 'my-x509-device';\nconst certificateFile = process.env.X509_CERT_FILE ?? 'path/to/device_cert.pem';\nconst keyFile = process.env.X509_KEY_FILE ?? 'path/to/device_key.pem';\n\nasync function main() {\n  if (!idScope || !certificateFile || !keyFile) {\n    console.error(\"Please set IOTHUB_DPS_ID_SCOPE, X509_CERT_FILE, and X509_KEY_FILE environment variables.\");\n    process.exit(1);\n  }\n\n  try {\n    const certificate = readFileSync(certificateFile).toString();\n    const privateKey = readFileSync(keyFile).toString();\n\n    // Create a new X509 security client\n    const securityClient = new X509Security(registrationId, certificate, privateKey);\n\n    // Create the provisioning client with HTTP transport and X509 security\n    const provisioningClient = ProvisioningDeviceClient.create(\n      idScope,\n      new Http(), // The HTTP transport from this package\n      securityClient\n    );\n\n    console.log(`Attempting to register device '${registrationId}' with DPS...`);\n\n    // Register the device\n    const result = await provisioningClient.register();\n\n    console.log('Registration result:');\n    console.log(JSON.stringify(result, null, 2));\n    console.log(`Device successfully registered with IoT Hub: ${result.assignedHub}`);\n    console.log(`Device ID: ${result.deviceId}`);\n  } catch (err: any) {\n    console.error('Device registration failed:', err.message);\n    if (err.responseBody) {\n      console.error('DPS Response:', err.responseBody);\n    }\n    process.exit(1);\n  }\n}\n\nmain();","lang":"typescript","description":"Demonstrates how to register a device with Azure IoT Hub Device Provisioning Service (DPS) using HTTP transport and X.509 certificate authentication."},"warnings":[{"fix":"Upgrade your Node.js runtime environment to version 14.0.0 or higher. The latest LTS version is generally recommended for production.","message":"As of the April 2022 release (v1.18.0) of the broader Azure IoT SDK for Node.js, including this package's dependencies, Node.js versions `>= 14.0.0` became the minimum supported runtime. Older Node.js 12 environments are no longer officially supported and may lead to unexpected behavior or failures.","severity":"breaking","affected_versions":">=1.18.0 (for related azure-iot-device, this package also aligns)"},{"fix":"Ensure all necessary packages are installed: `npm install --save azure-iot-provisioning-device azure-iot-provisioning-device-http azure-iot-security-x509` (or `-tpm` depending on your authentication method).","message":"This package provides only the HTTP transport component. For a complete device provisioning solution, you must also install `azure-iot-provisioning-device` (the client library) and either `azure-iot-security-x509` or `azure-iot-security-tpm` for device authentication. Neglecting to install these can lead to runtime errors when attempting to create a provisioning client.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Regularly update your `azure-iot-provisioning-device-http` and related Azure IoT SDK packages to the latest stable versions using `npm update` or `npm install <package-name>@latest`.","message":"Dependency vulnerabilities are frequently addressed in new releases across the Azure IoT SDK ecosystem. While the SDK team regularly updates dependencies, it's crucial for applications to keep their packages up-to-date to mitigate potential security risks and benefit from fixes.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Install the client package: `npm install --save azure-iot-provisioning-device`.","cause":"The core `azure-iot-provisioning-device` client package, a required peer dependency, is not installed in your project.","error":"Error: Cannot find module 'azure-iot-provisioning-device'"},{"fix":"Ensure `ProvisioningDeviceClient` is imported as a named export from `'azure-iot-provisioning-device'` like `import { ProvisioningDeviceClient } from 'azure-iot-provisioning-device';`.","cause":"The `ProvisioningDeviceClient` class was either not imported correctly (e.g., as a default import instead of a named import) or the `azure-iot-provisioning-device` package itself is missing.","error":"TypeError: ProvisioningDeviceClient.create is not a function"},{"fix":"Ensure you are passing `new Http()` and an instance of your chosen security client (e.g., `new X509Security(...)`) as the second and third arguments to `ProvisioningDeviceClient.create()`.","cause":"The `ProvisioningDeviceClient.create` method requires both a transport instance (like `new Http()`) and a security client instance (e.g., `new X509Security(...)` or `new TpmSecurity(...)`) to be provided as its second and third arguments.","error":"Error: Provisioning flow must have SecurityClient type and ProvisioningTransport type set."}],"ecosystem":"npm","meta_description":null}