Cloud API Not Working

Trying to work with the cloud API - but I’m obviously doing something wrong…

    user@host:~$ curl https://api.spark.io/v1/devices -d access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 

Returns:

{
  "ok": false,
  "errors": [
    "arg.deviceID is empty"
  ]
}

According to the documentation (http://docs.spark.io/#/api - “List devices the currently authenticated user has access to.”), I shouldn’t have to put a device ID in for the /v1/devices command - any ideas what I’m doing wrong?

And I can’t get /v1/access_tokens working either:

user@host:~$ curl https://api.spark.io/v1/access_tokens -u user@email.com:mypassword

Just returns:

[]

Any ideas? TIA.

Answer to the first one is that it needs to be:

curl -G ...

But still can’t get /v1/access_tokens working…

Yep, the -d option turns it into a POST request, but you need to make a GET request like this:

curl https://api.spark.io/v1/devices?access_token=123456789

You’re doing it right, it just returns for me as well…

Here’s an example using HTTP Basic Auth

FYI: the email:password is the BASE64 UTF-8 encoded characters after "Basic "

cc: @zach @Dave

1 Like

It looks like old access tokens that were generated before this new feature aren’t showing up. If you first create a new access token by doing POST /oauth/token, it should show up by then doing GET /v1/access_tokens

1 Like

Hmm, this does seem confusing. I believe this endpoint will only return existing access_tokens to you, it won’t create new ones.

Clarity:

  • GET /v1/access_tokens will retrieve an array of any access tokens created since we deployed this route last week.
  • POST /oauth/token will create a new token. You can have as many as you want.

As a backward compatibility workaround during the transition, you can still use the access token shown in the web IDE even if you haven’t created a new one. After you create your first one, the results will no longer be out of sync.