API not letting me connect?

The Netatmo API is a set of webservices allowing developers and third parties to access Netatmo device's data.
Post Reply
jmr
Posts: 5
Joined: 13 May 2022, 09:22

API not letting me connect?

Post by jmr »

Hi there,

I bought a Netatmo Weather Station at the beginning of this year to replace a 20 year old external temperature sensor that was doing serial over cat5. I was a little disappointed to find out that I had to talk to the company's servers to get my data, but after downloading and banging on the netatmo.sh script a bit, I was able to get my site working with it again (http://temp.jmr.is, if anyone's curious).

That is, until 3 mornings ago, when it abruptly stopped working. Here's the error I get:

[jmr@zuul temp]$ ./netatmo.sh -D
{"error":{"code":2,"message":"Invalid access token"}}

User/pass were still valid on the website (I can get on there and see my data manually). I tried changing my password, no luck. API still refuses to recognize me.

Has anyone else had this happen? My script connects every 5 minutes to pull the current readings, which I don't think is too obnoxious, but it HAD been doing it for several months without a break, which is unfortunately my use case for owning this thing.

I'd love to hear from anyone who has ideas for where to go next. I tried emailing customer support and did not hear back.

Cheers,
-J
kiboost
Posts: 676
Joined: 21 Jun 2013, 09:27

Re: API not letting me connect?

Post by kiboost »

Their website have change getting token when validating form. If you scrap their website instead of using the api you then have to adjust your script.
php-simpleNetatmoAPI Simple to use php API based on official API.
technarf
Posts: 4
Joined: 13 May 2022, 13:45

Re: API not letting me connect?

Post by technarf »

Hi,
I've exactly the same problem.
I used to collect data from https://api.netatmo.com/api/getmeasurecsv from several years.
Now I can"t.
I've seen the script doesn't retrieve the token anymore so I've done some modifications in the file and now, I can retrieve my token.
But when I try to retrieve my data I have a

Code: Select all

{"error":{"code":13,"message":"Operation is forbidden"}}
error.
If I change the url to https://api.netatmo.com/api/getmeasure and put the same options, I have some result but not in a csv format (which I need to give to my DB).
getmeasurecsv doesn't seem to be documented anymore.
Is there a way to have the data in a csv format ?
Thanks for your help.
jmr
Posts: 5
Joined: 13 May 2022, 09:22

Re: API not letting me connect?

Post by jmr »

I'm pretty sure, though it's been a while, that I got this netatmo.sh script off their own site somewhere. If there's a more preferred way to do it, please let me know... I'm really just looking for the simplest way to grab the most recent temperature reading from the outside temperature sensor. Seems like this would be a common thing for people to want to do? Kind of bizarre that it's so difficult.
technarf
Posts: 4
Joined: 13 May 2022, 13:45

Re: API not letting me connect?

Post by technarf »

The Netatmo support just told me this :
Indeed, this method has never been "publicly official" and documented on the developer portal. Unfortunately, it's not possible to access it anymore via an API call
In your case, you can have 2 solutions :
use as you said the /getmeasure method and find a way to convert the retrieved elements from the JSON response into a .csv
use our Webapp : https://my.netatmo.com/app/weather and go in parameters > Data management > Download. It's a manual operation (I don't know if you can find a way to automate it), but it's a solution to continue to get your data converted in a .csv format

For my use, I have to find a way to automate this, I hope I'll find a way to do this...
jmr
Posts: 5
Joined: 13 May 2022, 09:22

Re: API not letting me connect?

Post by jmr »

So they just disabled it? Sigh. This is the longest that site's been down since the late 90s.

Can you share with me the script you are using to fetch data from https://api.netatmo.com/api/getmeasure?

If so I will happily whip you up something to convert json to csv. I can do this most easily in PHP but can manage it in python as well I am sure.
technarf
Posts: 4
Joined: 13 May 2022, 13:45

Re: API not letting me connect?

Post by technarf »

Hi,
To fetch data I use this code (be indulgent, it is not optimized).

Code: Select all

#First I try to fetch the token
#The constants
USER="xxxxxx"
PASS="xxxxxxx"
CLIENT_ID="xxxxxxxxx"
CLIENT_SECRET="xxxxxxxxxxx"
SCOPE="read_station"
API_GETMEASURECSV="https://api.netatmo.com/api/getmeasure"
URL_LOGIN2="https://api.netatmo.com/oauth2/token"
DEVICE_ID="70:ee:xx:xx:xx:xx"
MODULE_ID="0x:00:00:xx:xx:xx"
#For the format I think this is no more used, but there is no error
FORMAT="csv"
#The type depends on the module for example you can add these types
TYPE="Temperature,Humidity,CO2,Noise,Pressure"
#DATES
#To have 24h of data
DATETIMEBEGIN=$(date +'%Y-%m-%d %H:%M:%S' --date='- 1440 minutes')
DATETIMEEND=$(date +'%Y-%m-%d %H:%M:%S')
DATEBEGIN="$(date --date="$DATETIMEBEGIN" "+%d.%m.%Y")"
TIMEBEGIN="$(date --date="$DATETIMEBEGIN" "+%H:%M")"
DATE_BEGIN="$(date --date="$DATETIMEBEGIN" "+%s")"
DATEEND="$(date --date="$DATETIMEEND" "+%d.%m.%Y")"
TIMEEND="$(date --date="$DATETIMEEND" "+%H:%M")"
DATE_END="$(date --date="$DATETIMEEND" "+%s")"


#In my code, I also urlencode all my constants just to be sure there is no problem (with the @ for instance)
USER="$(urlencode $USER)"
PASS="$(urlencode $PASS)"
DEVICE_ID="$(urlencode $DEVICE_ID)"
MODULE_ID="$(urlencode $MODULE_ID)"
TYPE="$(urlencode $TYPE)"
DATEBEGIN="$(urlencode $DATEBEGIN)"
TIMEBEGIN="$(urlencode $TIMEBEGIN)"
DATEEND="$(urlencode $DATEEND)"
TIMEEND="$(urlencode $TIMEEND)"
FORMAT="$(urlencode $FORMAT)"


#The options
OPTIONS="grant_type=password&client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&username=${USER}&password=${PASS}&scope=${SCOPE}"

#First, we have the response with access token and refresh token
TOKEN=$(curl  -H 'Content-Type: application/x-www-form-urlencoded' -d $OPTIONS $URL_LOGIN2)
#And now the access token and the refresh token (I don't know how to use it but just in case)
ACCESS_TOKEN=$(echo "${TOKEN}" | jq -r '.access_token')
REFRESH_TOKEN=$(echo "${TOKEN}" | jq -r '.refresh_token')

#Then I try to fetch the data

#The parameters
PARAM="access_token=$ACCESS_TOKEN&device_id=$DEVICE_ID&type=$TYPE&module_id=$MODULE_ID&scale=max&format=$FORMAT&datebegin=$DATEBEGIN&timebegin=$TIMEBEGIN&dateend=$DATEEND&timeend=$TIMEEND&date_begin=$DATE_BEGIN&date_end=$DATE_END&optimize=false"

#The Data
DONNEES=$(curl -H 'Content-Type: application/x-www-form-urlencoded' -d $PARAM $API_GETMEASURECSV)

#And finally, I try to have a usable data (this part is really work in progress)
DONNEES_FILTREES=$(echo "${DONNEES}" | jq -r '.body')
#The number of points
NB_ENREG=$(echo "${DONNEES_FILTREES}" | jq length)
#to display the data (or to write it in a file)
echo  $(echo "${DONNEES_FILTREES}" | jq '.')

And for example for 4 records, here is the result :

Code: Select all

{ "1652600710": [ 21.6, 59, 556, 35, 1014.9 ], "1652601012": [ 21.6, 59, 552, 35, 1014.8 ], "1652601314": [ 21.6, 59, 561, 35, 1014.9 ], "1652686277": [ 22.4, 58, 603, 36, 1018 ] }
First we have the timestamp of the record, and then the data (according to the TYPE data we have temperature, humidity, CO2, noise and pressure).
My main problem is that the timestamp is not a known value and is not into the brackets...
I would be very happy if you could transform this data to this one :

Code: Select all

1652600710;21.6;59;556;35;1014.9;
1652601012;21.6;59;552;35;1014.8;
1652601314;21.6;59;561;35;1014.9;
1652686277;22.4;58;603;36;1018;
I have to cron this job via a script, but I can execute some php or python code in my bash code, there is not a problem... ;)
Thanks for your help.
jmr
Posts: 5
Joined: 13 May 2022, 09:22

Re: API not letting me connect?

Post by jmr »

So I tried using your script to fetch my data, and I'm seeing the same error:

{"error":{"code":2,"message":"Invalid access token"}}

I did remove these two things because I'm not sure what they are supposed to be (and were not in my netatmo.sh script that I was originally using and now suddenly no longer works):

#CLIENT_ID="xxxxxxxxx"
#CLIENT_SECRET="xxxxxxxxxxx"

Can the company maybe chime in here with a preferred way to fetch this data? This stuff is useless to me otherwise and I will have to buy something else. Rather frustrating to have this happen after a few months' use, to say the least.
technarf
Posts: 4
Joined: 13 May 2022, 13:45

Re: API not letting me connect?

Post by technarf »

When you connect to dev.netatmo.com you have to create an "app" and it will create your Client ID and your Client Secret.
jmr
Posts: 5
Joined: 13 May 2022, 09:22

Re: API not letting me connect?

Post by jmr »

technarf wrote: 21 May 2022, 09:20 When you connect to dev.netatmo.com you have to create an "app" and it will create your Client ID and your Client Secret.
Thanks, will try this tomorrow.
Post Reply

Return to “Netatmo API”