Upload certificate in Azure device provisioning service

220 Views Asked by At

How to upload a new certificate programmatically in a device provisioning ? I am able to it manually but how can you upload it from a C# code ? Is there any Api ? I don't see anything about it on the Microsoft Documentation.

Moreover, is it possible to use the certificates from the Azure Key Vault ?

DPS screenshot

EDIT:

I found how to do it with Azure Cli, but I would like to do it with C#

az iot dps certificate create --dps-name MyDps --resource-group MyResourceGroup --name MyCertificate --path /certificates/Certificate.pem

https://learn.microsoft.com/en-us/cli/azure/iot/dps/certificate?view=azure-cli-latest#az_iot_dps_certificate_create

EDIT:

I found how to do it by API.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}?api-version=2018-01-22

https://learn.microsoft.com/en-us/rest/api/iot-dps/dps-certificate/create-or-update

1

There are 1 best solutions below

0
RahulKumarShaw On

Thank you draco951 for providing your answer in question section itself. I am keeping this in answer section to help other community member.

You can use an API in your C# code to upload a new certificate in a device provisioning Service

HTTP API --

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/provisioningServices/{provisioningServiceName}/certificates/{certificateName}?api-version=2018-01-22

and pass the certificate in request body

Request Body
{
  "certificate": "############################################"
}

Reference: https://learn.microsoft.com/en-us/rest/api/iot-dps/dps-certificate/create-or-update