REST API GET value for a single resource


#1

Hi,

I’ve a device that has 3 resources (Temp, Hum and HeatIdx). Is there a way through HTTP GET to get the value of, for instance the TEMP?

Currently I’ve tried the following:

https://api.thinger.io/v2/users/xxx/devices/yyy/dht22?authorization=***

And I’m getting protoson code for the 3 resources:

{"out":{"humidity":99.9,"temperature":12.3,"heat_index":12.1939}}

The goal is to get only individual readings so I can pass it to an Android Widget.

Thank you


#2

Hi,

in this case, just create a single resource for each reading (humidity, and temperature), like:

thing["humidity"] >> [](pson& out){
    out = dht.readHumidity();
};

thing["temperature"] >> [](pson& out){
    out = dht.readTemperature();
};

And just query each resource indiviually:

https://api.thinger.io/v2/users/xxx/devices/yyy/temperature?authorization=***

Hope it helps!


#3

i want to display my dht sensor data from thinger io api into my own website. what should i do, exactly what should i learn. i’m beginner and i don’t find tutorial yet for this issue.

i just have html code for where the data is displayed.


#4

Hello @Ahmad_Adeska,

There are different ways to do this integration. If you want to show the data represented in a widget, you can create it in a dashboard and then share it and introduce the hole dashboard into your website using an “Iref”.

But if you only want to extract the raw data, for example, one that is stored in a data bucket, you have to do two steps:

  1. create an access token with authorization to access to the bucket and read its data. You can learn how to manage access tokens in this part of thinger.io documentation: http://docs.thinger.io/console/#access-tockens
  2. call bucket API including the authorization and some parameters to select the last stored data as in the example below:

https://api.thinger.io/v1/users/jt/buckets/SensePoint/data?items=1&max_ts=0&sort=desc&authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJEYXNoYm9hcmRfREVNTyIsInVzciI6Imp0In0.y_cwNQqIak5oQQhElcmO0hEYKEodds3UB8SHW7Rlmko

when calling this api you will receive the hole row, so you will need to select the data you want to show with the specific key:
[{“ts”:1532878930886.0,“val”:{“batery”:3416.0,“humidity”:36.4385,“temperature”:27.8396}}]

A third option could be call directly to the device resource, as is explained in the second post of this conversation. Did you have problems with that?

Best!


#5

I already create an access token, but I have no idea how to call the bucket api.


I want to display it using php, but I only get the code for the led. whereas i use dht sensor. and this is an error that I got. Thank you in advance


#6

Hello @Ahmad_Adeska,

just to be sure that your HTTP query is well defined, try this:

  1. go to Thinger Endpoints tab
  2. create a new endpoint with HTTP configuration, GET message,and paste there your query as shown in the image below:
  3. Save the configuration and click in the “test endpoint” button on the right top of this interface
  4. test the endpoint by clicking in the bottom button and show the result message:

If this is working fie… the problem is on your PHP code,

Best