Cloud API for access_token

Hi again,

I was wondering if there is an endpoint/api where I can pass in my Spark.io email address and password and have it return the access_token to make the API calls?

I know the documentation mentions it using OAuth 2 but I didn’t see any endpoints/api.

Thanks again!

Carsten Dressler

Since I had no reply I took it upon myself to dig a little deeper. Here is what I found:

Authentication
POST to https://www.spark.io/sign-in
Headers: Content-Type: application/json
Body: {“username”:“youremailaddress”,“password”:“spark_password”}

This returns the following:

{
“username”: "xxxxx@xxx.com",
“auth_token”: {
“token”: “78n4xGh2aC_V8awk4jsA”,
“expires_at”: “2014-05-19T13:31:05Z”
}
}

To get access_token
GET https://www.spark.io/access-token
Headers: Content-Type: application/json
Authorization: Bearer 78n4xGh2aC_V8awk4jsA

NOTE: in the Authorization header, you need to add "Bearer " + token.

This returns the following:

{
“access_token”: “asdfjaskfdjfksajfalfjsfkfjdkfadf”,
“access_token_expires_at”: “2014-03-23T15:51:07+00:00”
}

Use this “access_token” to make requests to the API’s provided in the documents!

List devices the currently authenticated user has access to.

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

NOTE: I replaced the actual tokens/keys with fake keys. So the links do not work unless you run it on your own account and get your tokens/keys.

Hope this helps someone else!

Regards,
Carsten Dressler

2 Likes

I just tried this and it works :slight_smile: However is there any reason you wouldn’t just log into Spark Build http://spark.io/build and look at the Settings page? I’m guessing you are working on completely automating some kind of mesh network or something?

Yeah I do realize you can do it manually… but I wanted something more automatic :smiley:

I know this is getting dated but, is there an App that can display all: MAC Address; ID; Token & Devices to that account all on the same parsed page ?

You can, in fact, do this through the API:

http://docs.spark.io/#/api/authentication-generate-a-new-access-token

EDIT: Just realized that this post is a few months old, and this feature didn’t exist when it was posted :slight_smile: Well now it does!

Just following up on this. I’m trying to list my tokens via the Cloud API.

I’m getting a Unauthorised response back when I send my credentials in using Basic Auth in the header. i.e:

GET https://api.spark.io/v1/access_tokens Headers [Accept=application/json,Accept-Encoding=gzip, deflate,Authorization=BASIC BASE64_ENCODED_CREDENTIALS_HERE]

I’ve check my credentials, perhaps I’m missing something else?