Post Permission Denied

I’m trying to get a simple POST working to read a temperature variable. It works fine using curl in Terminal, but with Postman in Chrome it fails. (my ultimate goal is to use Python)

The preview from Postman looks like:

POST /v1/devices/54ff6e06666751515441567/temperature HTTP/1.1
Host: api.spark.io
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
access_token=<my access token>

The response I get is:

{
    "error": "Permission Denied",
    "info": "I didn't recognize that core name or ID, try opening https://api.spark.io/v1/devices?access_token=<my access token>"
}

Hi @matts

For a spark variable, you need to do a GET request, not a POST. IF you have a spark function, that takes a POST.

I tried GET, but it returns the same error.

https://api.spark.io/v1/devices/54ff6e06666751515441567/temperature?access_token=<my access token>

What does https://api.spark.io/v1/devices?access_token=<my access token> say?

I have struggled with very odd cut/paste problems that make it hard to see that either an access token is wrong (literally one digit got wrecked in the cut/paste) or the device ID.

I have to copy paste very carefully on my mac, and I cannot use notepad for that reason.

2 Likes

It says:

[
  {
    "id": "54ff6e066667515151441567",
    "name": "matt_core",
    "last_app": null,
    "last_heard": "2015-01-18T15:47:43.043Z",
    "connected": true
  }
]

That’s weird it was a copy/paste issue with the device ID. Some kind of encoding issue? I tried saving it in Sublime Text though. What worked was manually typing the device ID into Postman.

What I see is that the variable that you are trying to retrieve isn’t available on the core…

You might want to reflash the firmware again :wink:

After typing the device ID manually the GET request is working and I’m getting this response:

{
    "cmd": "VarReturn",
    "name": "temperature",
    "result": 24.21978021978022,
    "coreInfo": {
        "last_app": "",
        "last_heard": "2015-01-18T21:29:31.177Z",
        "connected": true,
        "deviceID": "54ff6e066667515151441567"
    }
}
2 Likes