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

changing Steps goal with fetch POST

Found this example, does anyone know what fbTok should contain?

 

fetch( 'https://api.fitbit.com/1/user/-/activities/goals/daily.json?steps=25000',
        {
                method: 'POST',
                headers: new Headers({
                        'Authorization': 'Bearer ' + fbTok,

                }),
                mode: 'cors',
        }
        ).then(processResponse)
        .then(function(data){ console.log('Request succeeded with response', data);})
        .catch(function(error){ console.log(error.message);});

 

it was taken as best answer from

https://community.fitbit.com/t5/Web-API-Development/How-to-POST-changes-to-daily-step-goals/m-p/2251...

Author | ch, passion for improvement.

Best Answer
10 REPLIES 10

Hi @Guy_ ,

 

The 'fbTok' in this example is referring the user's access_token obtained from authorization

Best Answer

@JohnFitbit  -  thanks, is authorisation needed when the userid is "-"?

 and if so do you have a sample code to help do that?

 

Alternatively is there another way to change the Steps goal via internal Api directly from the watch app without using the web Api ?

Author | ch, passion for improvement.

Best Answer

@Guy_ Yes, authorization is still needed if you're only pulling data from your Fitbit account. I don't have any sample code myself, but you can check the community resources for sample code. However, if you're just looking for a sample of how to format requests using "-", a request would look like this:

curl -X GET "https://api.fitbit.com/1/user/-/activities/date/2019-01-01.json" \
-H "accept: application/json" \
-H "authorization: Bearer <access_token>"

 

Regarding your 2nd question, the watch app pulls the goal data from the Fitbit app only, so there isn't a way to update the goal directly from the device. When you update the goal through the Fitbit app or Web API, the watch will need to sync to the app in order to update the new metrics.

Best Answer
0 Votes

@JohnFitbit-  thanks for the additional information. It is clear that the Web Api access is needed.

 

This will be an app that any user can install and run - looking at https://dev.fitbit.com/apps/new not sure this will get what is needed or is necessary.

 

Looking at the https://github.com/Fitbit/sdk-oauth app it is still not clear how or where the access_token is obtained to work any time for anyone.

 

Can you offer some more help, perhaps via PM, in case it is sensitive?

 

The calling sequence should probably be updated in the first post, as the example, as such?

https://api.fitbit.com/1/user/-/activities/goals/daily.json?type=steps&value=25000

 

 

Author | ch, passion for improvement.

Best Answer
0 Votes

Can anyone help?

Author | ch, passion for improvement.

Best Answer
0 Votes

@Gordon-C- is it possible to write a general app to be run by any user that updates their steps goal?

 

And if yes, how do you do the authorization automatically, or is there an API that can do the update on their own goals without authorization?

Author | ch, passion for improvement.

Best Answer
0 Votes

Regarding your question on obtaining the access token using the SDK, the sample code provided is for the companion application that runs on the phone.  You would need the user to go through the Web API consent process to share their data with your companion application.  It's possible this is done through the Settings API.   See https://dev.fitbit.com/build/reference/settings-api/#oauth-button.   After the consent process is complete, you'll have the access token.   The folks in the SDK section of the forum can help.

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

Yes, this can be done.  Your application will need to present your authorization URL somehow.  When the user click on it, they will be asked to log into their Fitbit account which is where we get their user id.   Once they complete the authorization flow, the application will be provided an access and refresh token specific to that user.   The application will need to store each access and refresh token for each user utilizing your application and update the tokens accordingly.  When a specific user wants to update their activity goal, you'll pull their current access token from your database, call the create activity goal endpoint using their access token.

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

Thank you so much @Gordon-C for taking the time to outline the process.

 

Unfortunately it is so terribly complex I doubt that any normal user would be able to do it, so it would be impractical to even develop such an app.

 

Many users struggle to even change the weather temperature units, so this would be outside the scope of most users, let alone the few who might be interested and benefit from such an app.

 

Would there be any other means that a user could simply update his own goal settings from an app without the need for such complexity?

Author | ch, passion for improvement.

Best Answer
0 Votes

The users can set their goals in their Fitbit account either through the web site or mobile application.   This help article explains how they can do this, https://help.fitbit.com/articles/en_US/Help_article/1955.htm.   If they need assistance, the users can contact our support team.

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