enableiot / iotkit-api

External API service for enableiot.com
https://dashboard.us.enableiot.com
BSD 2-Clause "Simplified" License
21 stars 7 forks source link

JSON call with REST #1

Closed Zouz83 closed 10 years ago

Zouz83 commented 10 years ago

Hi, I'm trying to find how to get the JSON data from my device. Could someone tell me if there is a way to do it by simple REST call like this api: http://api.openweathermap.org/data/2.5/forecast/daily?lat=1.350069&lon=103.696728&units=metric&cnt=7

i tryed that: https://enableiot.com/v1/api/accounts/9ccc...{my account ID}/data/search an i get error 404 Not found.

that would be usefull for calling the api from a device like a phone only get data no put or delete.

Thanks

jtaryma commented 10 years ago

It's probably just a problem with address; try using host dashboard.us.enableiot.com. The request URL should then be:

https://dashboard.us.enableiot.com/v1/api/accounts/9ccc...{your account ID}/data/search

Wiki page covering data API: https://github.com/enableiot/iotkit-api/wiki/Data-API

If you still experience this problem, please paste the full API request.

Zouz83 commented 10 years ago

thanks jrozestw I tryed now in my terminal curl https://dashboard.us.enableiot.com/v1/api/accounts/9ccc.../data/search -H 'Authorization: Bearer HeTS5q4M' Unauthorized 9ccc.... is the account ID where my galileo is sending data too HeTS5q4M is the activation code that i got from my account details am i missing something?

jtaryma commented 10 years ago

In the Authorization header you must provide your user JWT token. You can obtain your user token as explained here: https://github.com/enableiot/iotkit-agent/wiki/Authorization-API

pjholmes commented 10 years ago

What you'll need:

Authorization: Bearer eyJ0eXAi...

  1. Call the data search API documented here: https://github.com/enableiot/iotkit-api/wiki/Data-API#retrieve-data

Replace the accountId, deviceId and componentID and then POST.

POST accounts/{accountId}/data/search
{
  "from": 0,
  "targetFilter": {
    "deviceList": [
      "<device ID>"
    ]
  },
  "metrics": [
    {
      "id": "<component_id>",
      "op": "none" 
    }
  ]
}

If you'd like to see Python or Node.js examples of how to do this, please see:

https://github.com/enableiot/iotkit-samples/tree/master/api

--Patrick

Zouz83 commented 10 years ago

somewhere i still don't get that to work my call is:

curl -g https://dashboard.us.enableiot.com/v1/api/accounts/9ccc.../data/search -H 'Authorization: Bearer eyJ0eXAiOiJKV1Q...' --data '{"from": 0,"targetFilter": {"deviceList": ["00...."]}, "metrics": [{"id": "f659....", "op": "none"}]}'

{"code":400,"message":"Invalid request","errors":["targetFilter is missing and it is required","metrics is missing and it is required"," undefinedThe property {\"from\":0,\"targetFilter\":{\"deviceList\": is not defined in the schema and the schema does not allow additional properties"]}

I will continue looking and hopefully get that to work on objective c later on. Thanks a lot

Zouz83 commented 10 years ago

Finally for it to work i had to add the header -H 'Content-type: application/json' For the ones who want to try curl is: curl -g https://dashboard.us.enableiot.com/v1/api/accounts/{AccountID}/data/search -H 'Authorization: Bearer {Token here}' -H 'Content-type: application/json' -X POST --data '{"from":0,"targetFilter":{"deviceList":["{DeviceID}"]},"metrics":[{"id":"{here ID of the sensor}","op":"none"}]}'