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

Web API - Unable to create a Fitbit Subscription

ANSWERED

I followed the instructions for Implementing the Subscription API. I have created a web service endpoint, configured a subscriber, and verified the subscriber, but I cannot get the final step of Creating a Subscription to work.

I always receive the following error: 400 Bad Request. errorType: validation. fieldName: subscriberId. message: Invalid parameter subscriberId: 1234

Screenshot of how my app is configured, incl. that it indeed has the subscriber ID "1234".

Here's my Python code, using the automation platform Pipedream:

import requests

def handler(pd: "pipedream"):
  token = f'{pd.inputs["fitbit"]["$auth"]["oauth_access_token"]}'
  authorization = f'Bearer {token}'

  headers = {
    'accept': 'application/json',
    'content-length': "0",
    "X-Fitbit-Subscriber-Id": "1234",
    "Authorization": authorization
  }

  r = requests.post('https://api.fitbit.com/1/user/-/sleep/apiSubscriptions/pipedream-sleep.json', headers=headers)

  print(r.status_code, r.reason)
  return r.json()

What's the problem here?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Hey there, thanks for the reply. I found the problem. When using the automation service Pipedream (and presumably this also applies to similar services like Zapier or Make), one grants an OAuth2 authorization to only that service, i.e. presumably they have their own Fitbit app configured at dev.fitbit.com/apps. In any case, by using the code I mentioned in the OP, I was not using an authorization for my own app configured at dev.fitbit.com/apps, but rather for another, and so the subscriber ID I provided indeed didn't exist. Once I followed the OAuth2 tutorial from dev.fitbit.com/apps for my own app, received an OAuth2 access token, and used that token in my code, the rest of the setup worked fine.

Feedback from this experience, for the Fitbit API: I wish Fitbit's error message had been clearer here. It was "400 Bad Request. errorType: validation. fieldName: subscriberId. message: Invalid parameter subscriberId: 1234". But if this error message had also included the name and/or client ID of the Fitbit app I was authenticated with (e.g. "message: Invalid parameter subscriberId: 1234 for client ID: XYZ"), I would've caught this error instantly, instead of only after several hours of troubleshooting.

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

Hi @MondSemmel 

The information you provided looks correct to me.   Let me send you an email to request some additional information on your specific use case.   

 

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

@MondSemmel Are you updating the content-length header with the actual payload size when sending the request? I'm thinking the request might be failing because of this.

Best Answer
0 Votes

Hey there, thanks for the reply. I found the problem. When using the automation service Pipedream (and presumably this also applies to similar services like Zapier or Make), one grants an OAuth2 authorization to only that service, i.e. presumably they have their own Fitbit app configured at dev.fitbit.com/apps. In any case, by using the code I mentioned in the OP, I was not using an authorization for my own app configured at dev.fitbit.com/apps, but rather for another, and so the subscriber ID I provided indeed didn't exist. Once I followed the OAuth2 tutorial from dev.fitbit.com/apps for my own app, received an OAuth2 access token, and used that token in my code, the rest of the setup worked fine.

Feedback from this experience, for the Fitbit API: I wish Fitbit's error message had been clearer here. It was "400 Bad Request. errorType: validation. fieldName: subscriberId. message: Invalid parameter subscriberId: 1234". But if this error message had also included the name and/or client ID of the Fitbit app I was authenticated with (e.g. "message: Invalid parameter subscriberId: 1234 for client ID: XYZ"), I would've caught this error instantly, instead of only after several hours of troubleshooting.

Best Answer
0 Votes