How to call an IoT Central https REST API GET operator from an ESP8266

Kizito Kabanza 1 Reputation point

I am currently developing on an ESP8266 in order to interact with the IoT Central devices. I would like to fetch, via HTTPS, telemetry, and parameters of certain Devices from the IoT Central REST API.

However, there are no official or concrete libraries on how to do so (examples, code samples, etc). When using provided examples of Arduino httpClient or ESPWifi libraries, it always generates an error due to the authentication barrier.

The header ''Authorization: SAS Token...'' prior to the GET command also didn't work.


Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
354 questions
Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
317 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,030 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Roman Kiss 2,246 Reputation points


    Use the Postman client for test purpose to see that your GET request will work.

    The following screen snippet shows an example for getting a telemetry data:


    Note, that the Authorization header is the API token from the IoT Central App.


  2. Kizito Kabanza 1 Reputation point

    I tried again with this following logic:

      // wait for WiFi connection  
      if (( == WL_CONNECTED)) {  
        WiFiClient client;  
        HTTPClient http;  
        Serial.print("[HTTP] begin...\n");  
        if (http.begin(client, "https://....")) {  // HTTP  
          http.setAuthorization("Authorization: SharedAccessSignature sr=7...");  
          http.addHeader(F("Content-Type"), "application/json");        
          Serial.print("[HTTP] GET...\n");  
          // start connection and send HTTP header  
          int httpCode = http.GET();  
          // httpCode will be negative on error  
          if (httpCode > 0) {  
            // HTTP header has been send and Server response header has been handled  
            Serial.printf("[HTTP] GET... code: %d\n", httpCode);  
            // file found at server  
            if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {  
              const String& payload = http.getString();  
              remoteSwitch = payload;  
          } else {  
            Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());  
        } else {  
          Serial.printf("[HTTP} Unable to connect\n");  

    However, still ended as an error:


    0 comments No comments

  3. Johnson Yang 166 Reputation points Microsoft Employee


    There is one place I can see that you didn't pass the fingerprint for HTTPS request in line 9, you can follow the discussion here:

    You can also try to use the same way "content-type" header to add "Authorization" header.

    Hope this will help.


    0 comments No comments