homestatus access

The Netatmo API is a set of webservices allowing developers and third parties to access Netatmo device's data.
Post Reply
asterix
Posts: 2
Joined: 01 Dec 2018, 20:21

homestatus access

Post by asterix » 01 Dec 2018, 20:37

Bonsoir,

Je cherche a recuperer la température de mes Vannes depuis un script PHP. Pour cela l'API conseillée semble être homestatus. Or j'ai toujours une erreur "invalid access token" en accédant à ce endpoint. homesdata fonctionne bien, mais pas homestatus.

Je fais quelque chose de mal ou bien est-ce cassé ?

Céline
Posts: 37
Joined: 20 Nov 2017, 18:17

Re: homestatus access

Post by Céline » 03 Dec 2018, 18:56

Bonjour,

Est-ce que vous passez bien l'access_token dans le header ?

cf Bearer Authentication (en bas de https://dev.netatmo.com/en-US/resources ... nce/energy )
Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens. The name “Bearer authentication” can be understood as “give access to the bearer of this token.”
You must send the token in the Authorization header when making requests to Netatmo Home API
Authorization: Bearer
The Bearer authentication scheme was originally created as part of OAuth 2.0 in RFC 6750
Céline - Netatmo Team :D

asterix
Posts: 2
Joined: 01 Dec 2018, 20:21

Re: homestatus access

Post by asterix » 03 Dec 2018, 21:01


Vladislav
Posts: 2
Joined: 15 Jan 2019, 22:29

Re: homestatus access

Post by Vladislav » 15 Jan 2019, 22:36

Céline wrote:Bonjour,

Est-ce que vous passez bien l'access_token dans le header ?

cf Bearer Authentication (en bas de https://dev.netatmo.com/en-US/resources ... nce/energy )
Bearer authentication (also called token authentication) is an HTTP authentication scheme that involves security tokens called bearer tokens. The name “Bearer authentication” can be understood as “give access to the bearer of this token.”
You must send the token in the Authorization header when making requests to Netatmo Home API
Authorization: Bearer
The Bearer authentication scheme was originally created as part of OAuth 2.0 in RFC 6750
Hello,
I've got the same asterix's problem. When I use homesdata endpoint it works well, but homestatus request with the same access token leads to ERROR:
{"error":{"code":2,"message":"Invalid access_token"}}
Is it my fault or there are some problems with api?
Thank you a lot, really looking forward for the answer!

Céline
Posts: 37
Joined: 20 Nov 2017, 18:17

Re: homestatus access

Post by Céline » 16 Jan 2019, 18:16

Hi,

The access token needs to be set in your request header :

Authorization: Bearer <access_token>
Céline - Netatmo Team :D

Vladislav
Posts: 2
Joined: 15 Jan 2019, 22:29

Re: homestatus access

Post by Vladislav » 18 Jan 2019, 14:29

Céline wrote:Hi,

The access token needs to be set in your request header :

Authorization: Bearer <access_token>
You mean "homestatus" api method doesn't support URL based authentication like "homesdata" method?
https://api.netatmo.net/api/homesdata?a ... ome_id=YYY

UPD, sure Auth Header works well with "homesdata" method. So homesdata works with both types of authorization. Thats why there is such a misunderstanding.

d5c0d3
Posts: 1
Joined: 19 Jan 2019, 10:12

Re: homestatus access

Post by d5c0d3 » 19 Jan 2019, 10:39

Vladislav wrote:
Céline wrote:Hi,

The access token needs to be set in your request header :

Authorization: Bearer <access_token>
You mean "homestatus" api method doesn't support URL based authentication like "homesdata" method?
https://api.netatmo.net/api/homesdata?a ... ome_id=YYY

UPD, sure Auth Header works well with "homesdata" method. So homesdata works with both types of authorization. Thats why there is such a misunderstanding.
Finally, I found the solution for my problems using the 'homestatus' module! Thanks.

I use python and can confirm that 'homesdata' accepts url based authentication by giving the access_token as parameter.
However 'homestatus' would throw me an error 403 'Invalid access_token'. When the access_token is given in the request header it is working.

Would be helpful if the documentation on a module basis would state how to authenticate.

Here is my sample code (python) for anybody interested:

Code: Select all

...

## authentication code based on netatmo sample code
payload = {'grant_type': 'password',
           'username': "<your user name>",
           'password': "<your password>",
           'client_id':"<your client id>",
           'client_secret': "<your client secret>",
           'scope': 'read_thermostat'}
try:
	response = requests.post("https://api.netatmo.com/oauth2/token", data=payload)
	response.raise_for_status()
	access_token=response.json()["access_token"]
	refresh_token=response.json()["refresh_token"]
	expires_in=response.json()["expires_in"]
	scope=response.json()["scope"]
	print("Your access token is        : ", access_token)
	print("Your refresh token is       : ", refresh_token)
	print("Your access token expires in: ", expires_in)
	print("Your scopes are:", scope)
except requests.exceptions.HTTPError as error:
	print(error.response.status_code, error.response.text)

## Endpoint: https://api.netatmo.com/api/homesdata 
## used to get the necessary ID's for subsequent API calls
## authentication via params
params = {
	'access_token': access_token
	}
try:
    response = requests.get("https://api.netatmo.com/api/homesdata", params=params)
    response.raise_for_status()
    data = response.json()["body"]
except requests.exceptions.HTTPError as error:
    print(error.response.status_code, error.response.text)

# Endpoint: https://api.netatmo.com/api/homestatus 
# reads current measures
# need identification via the request header!
headers = { 
	'Authorization': 'Bearer ' + access_token
}
params = {
	'home_id': home_id #,
	#'device_id': '[YOUR_DEVICE_ID]'
	}
	
try:
	response = requests.post("https://api.netatmo.com/api/homestatus", params=params, headers=headers)
	response.raise_for_status()
	data = response.json()["body"]
	print(data)
except requests.exceptions.HTTPError as error:
	print(error.response.status_code, error.response.text)

Céline
Posts: 37
Joined: 20 Nov 2017, 18:17

Re: homestatus access

Post by Céline » 31 Jan 2019, 13:46

You should put your access token in the header for all calls you're making. All endpoints are supporting this method.
Céline - Netatmo Team :D

Post Reply

Return to “Netatmo API”