invalid_grant

The Netatmo API is a set of webservices allowing developers and third parties to access Netatmo device's data.
Post Reply
Errok
Posts: 5
Joined: 16 Aug 2017, 15:37

invalid_grant

Post by Errok »

Hello all

I have problem with netatmo API. When I try to create client credentials with read_station grant, I receive always invalid_grant. :cry:

Have you the same problem ?

My Node js code :

Code: Select all

var https = require("https");
const querystring = require('querystring');

var options = {
    hostname: 'api.netatmo.com',
    path: '/oauth2/token',
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
};

var params = querystring.stringify({'grant_type': "password",
    'username': "xxxxxxxxxxxxxxxxxx",
    'password': "xxxxxxxxxxxxxxxxxx",
    'client_id':"xxxxxxxxxxxxxxxxxx",
    'client_secret': "xxxxxxxxxxxxxxxxxx",
    'scope': "read_station"});

var callback = function(response) {
    response.on('error', function(e) {
        console.log('error', e);
    });
    var res = '';

    response.on('data', function (chunk) {
        res += chunk;
    });

    response.on('end', function () {
        res = JSON.parse(res);
        if (response.statusCode == '200') {
            var access_token = res.access_token;
            var refresh_token = res.refresh_token;
            var scope = res.scope;
            console.log("Your access_token is:", access_token);
            console.log("Your refresh_token is:", refresh_token);
            console.log("Your scopes are:", scope);
        } else {
            console.log('status code:', response.statusCode, '\n', res);
        }
    });
};


var req = https.request(options, callback);
req.on('error', function(e) {
    console.log('There is a problem with your request:', e.message);
});

req.write(params);
req.end();
Errok
Posts: 5
Joined: 16 Aug 2017, 15:37

Re: invalid_grant

Post by Errok »

There is someone ?
PhilHornby
Posts: 87
Joined: 26 Oct 2016, 14:51
Location: Devon, UK
Contact:

Re: invalid_grant

Post by PhilHornby »

I'm not overly familiar with JavaScript, but I think the format of the data you are sending to the API is not quite correct?

I can't see the "&" character between parameters (but maybe some .JS function adds those automatically). Compared with what I send (which works), you seem to have a lot of "quote" characters that I don't, and ":" instead of "=". I don't know if it helps, but here is some (anonymised) data, that I captured using Telerik Fiddler, from a successful API session:-

Code: Select all

POST https://api.netatmo.com/oauth2/token HTTP/1.1
User-Agent: curl/7.30.0
Host: api.netatmo.com
Accept: */*
Content-Length: 206
Content-Type: application/x-www-form-urlencoded

grant_type=password&username=wwwwwww@xxxxxx.yy.zz&password=formetoknow!/&client_id=1234567890abcdef01234567&client_secret=aJXdfh48d8fdk458gf847548dfjhfJHJDHGD&B&%SDcxq&scope=read_thermostat write_thermostat
My client is a "dos" batch script, using Curl.exe.
Errok
Posts: 5
Joined: 16 Aug 2017, 15:37

Re: invalid_grant

Post by Errok »

Thanks for your help but I have the same response with (anonymised) :

Code: Select all

curl -d "grant_type=password&username=test@test.fr&password=zzzzzzzzz&client_id=xxxxxxxxxxxxxxxxxx&client_secret=yyyyyyyyyyyyy&scope=read_thermostat" -X POST https://api.netatmo.com/oauth2/token
Have you complet parameters on admin web app page : https://dev.netatmo.com/myaccount/ ?

I left empty :
- Redirect URI
- Webhook URL
- App Website
- Company
- Company website

with :

- APP STATUS : activate

it's very strange...
PhilHornby
Posts: 87
Joined: 26 Oct 2016, 14:51
Location: Devon, UK
Contact:

Re: invalid_grant

Post by PhilHornby »

I do have a redirect URI = but it points to a 404 error ;-)
Webhook is blank
App website is a valid URL - but nothing to do with the app ;-)
Company is "ACME Dodge Software Inc." ;-)
Company website is the same as App website - valid, but irrelevant ;-)
Errok
Posts: 5
Joined: 16 Aug 2017, 15:37

Re: invalid_grant

Post by Errok »

Does not work :( same response.... Thanks anyway for your help...
Post Reply

Return to “Netatmo API”