Permission denied reading a variable

I registered a variable the standard way (I think)

int position = 0;
void setup()
{
     Spark.variable("position", &position, INT);
}

loop()
{
    update position;
}

However, when I
$ curl "https://api.spark.io/v1/devices/0123456789abcdef/position?access_token=fedcba9876543210"
I get
{
“error”: “Permission Denied”
}

Help?

Hey @rmd6502,

I checked the server logs and it looks like you’re not hitting a core you own. Your requests have a deviceID starting with 55, and your core IDs start with 48, and 53. Try adjusting that and I’m guessing you’ll be set!

Also you can check and see what functions and variables are exposed by your firmware if you open up this url in your browser (make sure you change the deviceID / access_token :slight_smile: )

https://api.spark.io/v1/devices/0123456789abcdef?access_token=fedcba9876543210

Thanks,
David

Wow, seems I doubled the ‘5’ at the front. (redfaced)

No worries! Glad it’s working. :slight_smile:

I also have an issue with variables exposed through the Spark API.

It works OK from the terminal window in my Mac, but it doesn’t work from a browser when I copy/paste the URL on the same Mac. And it doesn’t work either when I try from my iPhone using an app such as iCurlHTTP.

In both cases I get a “Permission denied” response. I’ve double and triple checked both the Core ID (starting with 53ff6b065067544 …) and the auth token. Any hint?

Thanks for your help!

Hi @ChristopheLauer,

Make sure if you’re reading a variable that the HTTP method is “GET.” You’ll only get permission denied if your core id / access token are wrong, or if you’re using the wrong kind of request method.

Thanks!
David

Thanks Dave for your answer. I’m not sure I fully get it though: I suppose that the variable is accessible via the GET method since it works via Curl on my Mac but the exact same request from a curl app on my iPhone fails. Also the same Curl request fails for another team member on his own Mac. What is the auth token based on? Is it shareable? Is there something host based in it?

Hi @ChristopheLauer,

The access token is sharable (although should probably be kept private). I’m guessing the problem is with how the request is being made between the different apps.

Thanks,
David