Can't get Spark api working [SOLVED]

Documentation is confusing

Can’t get access token

Docs: http://screenshots.ryotsuke.ru/scr_b25cb2cbc525.png

I am sending same data to POST, but get 400 response http://screenshots.ryotsuke.ru/scr_f8cb5556ac7b.png

So I’ve taken access_token and valid device id from GUI, still failing: http://screenshots.ryotsuke.ru/scr_898559c00814.png now 404

Same as in docs http://screenshots.ryotsuke.ru/scr_11b967f254b1.png

What is wrong?

Can you make Documentation more clear about POST headers required?

Hi @ryotsuke,

In the photos it shows you are sending your password as “password” is that correct?

Make sure you check your device’s endpoint: https://api.spark.io/v1/devices/your_core_id?access_token=access_token and make sure your function is properly exposed as a function. It’s possible you flashed firmware with this but it didn’t flash properly.

Thanks,
David

I wouldn’t post real password on screenshot )

Using endpoint url in broswer works: http://screenshots.ryotsuke.ru/scr_0165a4819ac2.png

Should access token be in GET request part?

After reflashing core it started working, so 2nd question was about non-flashed firmware

So now only question #1 remains - how do I get token with POST request?

Ah, awesome! :smile:

Access token should be in the url for GET requests, and in the body for POST requests. I think you were hitting this endpoint already, but zachary posted about the oauth endpoint here: https://community.spark.io/t/get-automatically-device-id-and-access-token/2239/3

I have a wrapper for this endpoint in node that I’m using for the command line interface, it looks something like…

var request = require('request');
 request({
        uri: "https://api.spark.io/oauth/token",
        method: "POST",
        form: {
            username: user,
            password: pass,
            grant_type: 'password',
            client_id: client_id,
            client_secret: "client_secret_here"
        },
        json: true
    }, function (error, response, body) {
        if (body && body.access_token) {
            console.log("Got an access token! " + body.access_token);
        }
    });

Hope that helps!
Thanks,
David

what is client_id here and client_secret?

I basically have a very simple webpage with jquery sending all this stuff like this http://screenshots.ryotsuke.ru/scr_9dd71e240b72.png

I’ve changed URL to https://api.spark.io/v1/oauth/token intead of https://api.spark.io/oauth/token (Docs are wrong?)
Still failing: http://screenshots.ryotsuke.ru/scr_d71c42f65cd4.png

Ahh typo, my bad, “v1” shouldn’t be in the oauth login url.

cleint_id, and client_secret would normally be per-user approved clients and secrets generated from the API, but for the sake of getting everyone up and running quickly, we’ve left those open ended for the moment, so they can be whatever you like right now.

Thanks,
David

Typo or not it is not working in both cases :-/

Also how can firmware not be flashed? I have no error messages, nothing weird happening on core.
I’ve added one more Spark function and flashed 2 times already - function is not appearing. Core is not hang - old functions are working.

This way cloud software looks highly unreliable

Can Spark function 404 if something is wrong in this particular function?
UPD: function itself work ok http://screenshots.ryotsuke.ru/scr_decd683b90c5.png

Every Spark function works except “servo” one. Can’t see an issue
Also it is not exposed to url http://screenshots.ryotsuke.ru/scr_6b74a6c00eb0.png

Hi @ryotsuke,

Oh! I didn’t realize you had a bunch of other working functions, that makes a big difference! Right now Spark.function is limited to 4 functions so that more ram is available. That’s mentioned in the docs here: http://docs.spark.io/#/firmware/cloud-spark-function

I’m thinking we need to make this a #define so that people can add extra functions more easily. I’ll enter a bug for that.

Thanks!
David