Skip to content

Make a GET request to a Dataverse

Miguel Tomas Silva edited this page Oct 15, 2022 · 10 revisions

To make a custom GET request to a Dataverse one needs to call the function method String GetInfoFromDataverse(String URL); in the following piece of code a GET request is made to request lock state on a specific dataset id:

Dataverse dataverse = new Dataverse();

String id="dataset id";
String url="/api/datasets/"+ id +"/locks";

String rawResponse = dataverse::GetInfoFromDataverse(url);

The function method returns a string with the rawResponse from the dataverse server. This raw response can next be digested into JSon using the appropriate Json class library. On embedded firmware programming of smart devices, the ArduinoJson library must be included in the project #include <ArduinoJson.h>. And add the following piece of code to do Json serialization of the response string.


      bool uploadStatusNotOK=true;
      String rawResponse = GetInfoFromDataverse("/api/datasets/"+ datasetInfoJson["data"]["id"] +"/locks");
      const size_t capacity =2*rawResponse.length() + JSON_ARRAY_SIZE(1) + 7*JSON_OBJECT_SIZE(1);
      DynamicJsonDocument datasetLocksJson(capacity);  
      // Parse JSON object
      DeserializationError error = deserializeJson(datasetLocksJson, rawResponse);
      if (error) {
        mserial.printStr("unable to retrive dataset lock status. Upload not possible. ERR: "+error.f_str());
        //mserial.printStrln(rawResponse);
        return;
      }else{
         String stat = datasetInfoJson["status"];
         if(datasetInfoJson.containsKey("lockType")){

           String locktype = datasetInfoJson["data"]["lockType"];           
           mserial.printStrln("There is a Lock on the dataset: "+ locktype); 
           mserial.printStrln("Upload of most recent data is not possible without removal of the lock.");  
           // Do unlocking 
           // ...     
         }else{
            mserial.printStrln("The dataset is unlocked. Upload possible.");
            uploadStatusNotOK=false;     
         }
      }
    }
  

More info about this particular library can be found at the ArduinoJson website here.

Clone this wiki locally