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

web api: Trouble creating subscriptions for each scope

Hi

We are implementing a web collector for a medical research project. For each scope a user authorizes we want to create subscriptions. The scopes we are most interested in are heart rate, sleep, respitory rate, oxygen saturation, how ever we encourage our study participants to share as much data as possible.

Our subscriptions are not created in any particular order. The first call to apiSubscriptions creates a subscription for profile. Given there is no web hook, we decided to add it sleep.This way we would call it at most once a day.

INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/sleep/apiSubscriptions/XXXXXX-profile.json
INFO: subResponse.getCode(): 201
INFO: subResponse.getBody(): {"collectionType":"sleep","ownerId":"XXXXXX","ownerType":"user","subscriberId":"123","subscriptionId":"XXXXXX-profile"}


The next couple of subscription are for respiratory_rate, oxygen_saturation, and hrv. Theses streams are created when some one sleeps. Notice we get responce code 409. Any idea what we our bug is?

INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/sleep/apiSubscriptions/XXXXXX-respiratory_rate.json
INFO: subResponse.getCode(): 409
subResponse.getBody(): {"collectionType":"sleep","ownerId":"XXXXXX","ownerType":"user","subscriberId":"123","subscriptionId":"XXXXXX-profile"}


INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/sleep/apiSubscriptions/XXXXXX-oxygen_saturation.json
INFO: subResponse.getCode(): 409
INFO: subResponse.getBody(): {"collectionType":"sleep","ownerId":"XXXXXX","ownerType":"user","subscriberId":"123","subscriptionId":"XXXXXX-profile"}


heartrate: (hrv, hr, sleep):
INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/null/apiSubscriptions/XXXXXX-heartrate.json
INFO: subResponse.getCode(): 400
INFO: subResponse.getBody(): {"errors":[{"errorType":"validation","fieldName":"collectionType","message":"The value \"null\" is not a valid value for field Collection Type"}]}


We hung the remaining apiSubscriptions off of sleep as a place holder for now. In the future we will only want to call these at most once a day. Notice that the we have not ordered the calls to apiSubscriptions in any particular way

sleep: (sleep)
INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/sleep/apiSubscriptions/XXXXXX-sleep.json
INFO: subResponse.getCode(): 409
INFO: subResponse.getBody(): {"collectionType":"sleep","ownerId":"XXXXXX","ownerType":"user","subscriberId":"123","subscriptionId":"XXXXXX-profile"}


location: (sleep)
INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/sleep/apiSubscriptions/XXXXXX-location.json
INFO: subResponse.getCode(): 409
INFO: subResponse.getBody(): {"collectionType":"sleep","ownerId":"XXXXXX","ownerType":"user","subscriberId":"123","subscriptionId":"XXXXXX-profile"}

social: (sleep)
INFO: subs url: https://api.fitbit.com/1/user/XXXXXX/sleep/apiSubscriptions/XXXXXX-social.json
INFO: subResponse.getCode(): 409
INFO: subResponse.getBody(): {"collectionType":"sleep","ownerId":"XXXXXX","ownerType":"user","subscriberId":"123","subscriptionId":"XXXXXX-profile"}


Any idea what our bug is ?

What is best practice?

Kind regards

Andy

Best Answer
0 Votes
0 REPLIES 0