Search code examples
azurerestazure-iot-hub

Azure IoT Hub Rest API returns "InvalidProtocolVersion;Bad Request"


I'm new to Azure IoT Hub

What I'm trying to do is remove pending commands for a device in the IoT Hub by using Azure IoT Hub's REST API as shown here here

But I keep getting the same error "InvalidProtocolVersion;Bad Request"

see this postman request

I added a SAS Token in the header and changed the api-version parameter but nothing works.

Can anybody help ?


Solution

  • I added a SAS Token in the header and changed the api-version parameter but nothing works.

    According to documentation:

    • DELETE operations may include the following header: If-Match = [*|<etag from get>]

    Alternatively, you can use the following documented Azure CLI command to purge cloud-to-device message queue for a target device:

    az iot device c2d-message purge --device-id
                                    [--hub-name]
                                    [--login]
                                    [--resource-group]
    

    Updated answer:

    According to Eyasu Bogale:

    SAS token did not have all the permission it needed. Generated it using az iot hub generate-sas-token -n roboatiothub --policy iothubowner (not registryRead) and now it works (even without the If-Match header)

    References: Azure IoT Hub InvalidProtocolVersion,Control access to IoT Hub and az iot hub generate-sas-token