'Too many requests' error on Azure IOT central create job API

67 Views Asked by At

Getting the below error in the job api while creating scheduled job for alerts. error screenshot

Here is the link to Microsoft documentation which states the limit for the requests, but we are creating far less request from application.

https://learn.microsoft.com/en-us/rest/api/iotcentral/throttling

Tried requesting few times, expectation is that Too many requests error should not come

1

There are 1 best solutions below

4
Sampath On

The below steps below to create a job in IoT Central Application.

First Create a device in IoT Central:

PUT https://{subdomain}.{baseDomain}/api/devices/{deviceId}?api-version=2022-07-31
Authorization:  API tokens
Content-Type: application/json

To create and use an API token:

  • Open your IoT Central application in the browser and go to Permissions > API tokens.
  • Click Generate token. You'll be prompted to give it a name and choose a role. The role determines what a client using this token is authorized to do in this application.
  • Generate the token and copy the value. The value is a secret and will only be shown once.

Body:

{
  "displayName": "Device group 1",
  "description": "Custom device group.",
  "filter": "SELECT * FROM devices WHERE $template = \"dtmi:modelDefinition:dtdlv2\" AND $provisioned = true"
}

enter image description here

  • Add device templates in Azure IoT Central with the REST API.
PUT https://{your-app-subdomain}.azureiotcentral.com/api/deviceTemplates/dtmi:contoso:mythermostattemplate;1?api-version=2022-07-31

Authorization:  API tokens
Content-Type: application/json

Body:

{
    "displayName": "Thermostat",
    "@id": "dtmi:contoso:mythermostattemplate;1",
    "@type": [
        "ModelDefinition",
        "DeviceModel"
    ],
    "@context": [
        "dtmi:iotcentral:context;2",
        "dtmi:dtdl:context;2"
    ],
    "capabilityModel": {
        "@id": "dtmi:contoso:Thermostat;1",
        "@type": "Interface",
        "contents": [
            {
                "@type": [
                    "Telemetry",
                    "Temperature"
                ],
                "description": "Temperature in degrees Celsius.",
                "displayName": "Temperature",
                "name": "temperature",
                "schema": "double",
                "unit": "degreeCelsius"
            },
            {
                "@type": [
                    "Property",
                    "Temperature"
                ],
                "description": "Allows to remotely specify the desired target temperature.",
                "displayName": "Target Temperature",
                "name": "targetTemperature",
                "schema": "double",
                "unit": "degreeCelsius",
                "writable": true,
                "decimalPlaces": 1,
                "displayUnit": "C",
                "maxValue": 80,
                "minValue": 50
            },
            {
                "@type": [
                    "Property",
                    "Temperature"
                ],
                "description": "Returns the max temperature since last device reboot.",
                "displayName": "Max temperature since last reboot.",
                "name": "maxTempSinceLastReboot",
                "schema": "double",
                "unit": "degreeCelsius"
            },
            {
                "@type": "Command",
                "description": "This command returns the max, min and average temperature from the specified time to the current time.",
                "displayName": "Get report",
                "name": "getMaxMinReport",
                "request": {
                    "@type": "CommandPayload",
                    "description": "Period to return the max-min report.",
                    "displayName": "Since",
                    "name": "since",
                    "schema": "dateTime"
                },
                "response": {
                    "@type": "CommandPayload",
                    "displayName": "Temperature Report",
                    "name": "tempReport",
                    "schema": {
                        "@type": "Object",
                        "fields": [
                            {
                                "displayName": "Max temperature",
                                "name": "maxTemp",
                                "schema": "double"
                            },
                            {
                                "displayName": "Min temperature",
                                "name": "minTemp",
                                "schema": "double"
                            },
                            {
                                "displayName": "Average Temperature",
                                "name": "avgTemp",
                                "schema": "double"
                            },
                            {
                                "displayName": "Start Time",
                                "name": "startTime",
                                "schema": "dateTime"
                            },
                            {
                                "displayName": "End Time",
                                "name": "endTime",
                                "schema": "dateTime"
                            }
                        ]
                    }
                }
            },
            {
                "@type": [
                    "Property",
                    "Cloud",
                    "StringValue"
                ],
                "displayName": "Customer Name",
                "name": "CustomerName",
                "schema": "string"
            }
        ],
        "description": "Reports current temperature and provides desired temperature control.",
        "displayName": "Thermostat"
    }
}


enter image description here

  • Then create Jobs with REST API IoT Central.
PUT https://{your-app-subdomain}.azureiotcentral.com/api/jobs/{jobId}?api-version=2022-07-31
Authorization:  API tokens
Content-Type: application/json

Body:

{
  "displayName": "My Job",
  "group": "group1",
  "data": [
    {
      "type": "property",
      "target": "dtmi:contoso:mythermostattemplate;1",
      "path": "targetTemperature",
      "value": 90
    }
  ]
}

enter image description here

enter image description here