0

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

draco951
  • 226
  • 3
  • 13
  • if you enable the debug mode on az ci, you will be able to check which apis are called. – Thomas Sep 02 '21 at 12:55
  • Hello , you can accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). This can be beneficial to other community members. Thank you – RahulKumarShaw Oct 07 '21 at 14:23

1 Answers1

0

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

RahulKumarShaw
  • 4,192
  • 2
  • 5
  • 11