400 invalid grant [solved]

I got a Spark working with the Relay sketch. I performed the curl commands from my Mac, without any issue, and was able to turn on/off the LEDs connected to the relays. However, when I transplanted the exact same command to another computer (server at Amazon), I got

{
  "code": 400,
  "error": "invalid_grant",
  "error_description": "The access token provided is invalid."
}

and I can’t find how to change the authorization token to allow the new server to access the relays.

The curl command in both cases was similar to:

curl -H "Authorization: Bearer BIG-NUMBER" https://api.spark.io/v1/devices/BIG-HEX-NUMBER/relay -d params=r3,LOW

The access token can be found (and reset) on the settings page in the build IDE at spark.io/build
Random question: are you sure that server supports curl?

Yes, it supports curl, otherwise I could not get the JSON encoded answer back. I realize I can reset the token, but it works just fine from my Mac, but not the Ubuntu 14.04 system at AWS. I thought there might be something system specific in the token, like a dependency on the source IP address.

Hey @kimtoms,

There’s probably no such system specific requirement. :smiley:

Can you try this "https://api.spark.io/v1/devices?access_token=xxxx"

That was interesting. Using the form -d access_token=NUMBER, it worked. I had used the -H form because the documentation said it ‘always works’, but it did not. (in retrospect, I think it means ‘works for both GET, POST, and PUT, not is more reliable’).

I’m not sure what the issue is there, but thanks for helping me get it working!

1 Like

Cool! Is there something we can improve in terms of the Docs?

Let me know or you can always send in a PR for our docs at https://github.com/spark/docs

Thanks! :smiley:

Ok, I haven’t seen that before. It seems it was a paste error. I copy/pasted it with my mouse from one terminal window to the other, and it changed. Sorry for the mistake :frowning:

1 Like