Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ERROR while trying Get Sleep Logs by Date Range

ANSWERED

Hi,
I am currently trying to get the sleep data over a period of time, but it seems as the API isn't understanding my request, although it is written in exact the same way, as the documentation says:

GET https://api.fitbit.com/1.2/user/[user-id]/sleep/date/[startDate]/[endDate].json

So I am requesting with:

GET https://api.fitbit.com/1.2/user/-/sleep/date/2018-04-15/2018-04-16.json

What I get is:

{"errors":[{"errorType":"validation","fieldName":"date","message":"Invalid date: 2018-04-15/2018-04-16"}]}

Looks like the API takes "2018-04-15/2018-04-16" as one date param instead of two, like it should.

Can you guys help me, or fix this please, as I'll need large amounts of sleep data and currently I can only get one sleep data for one day with each request...


Thanks 🙂 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Hi there,

@danmana Encoding was my guess as well, but it turned out, it was simple stupidity by myself 😄


@GordonFitbit contacted me via PM and we figured out, I was using POST method instead of GET..

I didn't notice this, as the request for daily sleep was working perfect, but Gorden luckily saw it in the Fitbit logs.

Thanks for helping me with this!

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

Hi wangerowski,

 

I was not able to reproduce the error message you are receiving.  Have you tried executing the same call within the Fitbit Web API explorer tool?

 

https://dev.fitbit.com/build/reference/web-api/explore/#/Sleep/sleep3

 

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

Hi Gordon!

Call via Web API is giving me a 200.

But why isn't it working then with my request 😞

Obviously the api is using both dates as one param, when I try to call.
Do you have any idea why this could be happening? 

Best Answer
0 Votes

Hi,

 

I'm unable to reproduce the error with the URL you have given. Everything works (I tried in postman).

 

Are you sure you're not encoding the slash between the dates?

Best Answer
0 Votes

Hi there,

@danmana Encoding was my guess as well, but it turned out, it was simple stupidity by myself 😄


@GordonFitbit contacted me via PM and we figured out, I was using POST method instead of GET..

I didn't notice this, as the request for daily sleep was working perfect, but Gorden luckily saw it in the Fitbit logs.

Thanks for helping me with this!

Best Answer
0 Votes