Create Subscription
chevron down
 

Create Subscription

Creates a subscription to notify the application when a user has new data available. See Creating a Subscription for more information.

Scope: See collection-path URI Argument


Request

POST /1/user/[user-id]/[collection-path]/apiSubscriptions/[subscription-id].json

URI Arguments
user-id required The encoded ID of the user. Use "-" (dash) for current logged-in user.
collection-path optional Collection of data to retrieve notifications. If not provided, a subscription will be created for all collections. If both all and specific collection subscriptions are created, duplicate notifications will be received. Each subscriber can have only one subscription for a specific user's collection.

Supported: activities | body | foods | sleep | userRevokedAccess

The user must consent to the proper OAuth 2.0 scope before a subscription can be created for the collection. The list of requirements are:

  • activities collection requires activity scope.
  • body collection requires weight scope.
  • foods collection requires nutrition scope.
  • sleep collection requires sleep scope.
  • userRevokedAccess collection does not require any scopes.
  • If no collection specified, activity, nutrition, profile, settings, sleep, weight scopes are required.
subscription-id required The unique ID of the subscription created by the API client application. The value provides a way to associate an update with a particular user stream in your application.

Maximum length: 50 characters

Request Headers
authorization required Specify the token type and Fitbit user’s access token.
Token type: Bearer
accept optional The media type of the response content the client is expecting.
Supported: application/json
accept-language optional The measurement unit system to use for response values. See Localization.
accept-locale optional The locale to use for response values. See Localization.
content-length required According to RFC 7230, section 3.3.2, this HTTP request requires the Content-Length header field containing the anticipated size of the payload body.
X-Fitbit-Subscriber-Id optional The ID of the subscriber to receive notifications, as defined on dev.fitbit.com. If not present, the default subscriber is used.

Examples
POST https://api.fitbit.com/1/user/-/apiSubscriptions/320.json
POST https://link>://api.fitbit.com/1/user/-/activities/apiSubscriptions/320json
POST https://api.fitbit.com/1/user/-/body/apiSubscriptions/320.json
POST https://api.fitbit.com/1/user/-/foods/apiSubscriptions/320.json
POST https://api.fitbit.com/1/user/GGNJL9/sleep/apiSubscriptions/320.json
POST https://api.fitbit.com/1/user/GGNJL9/userRevokedAccess/apiSubscriptions/320.json
curl -X POST "https://api.fitbit.com/1/user/-/apiSubscriptions/320.json" \
-H "accept: application/json" \
-H "authorization: Bearer <access_token>" \
-H "content-length: <message_body_size>"

curl -X POST "https://api.fitbit.com/1/user/-/activities/apiSubscriptions/320.json" \
-H "accept: application/json" \
-H "authorization: Bearer <access_token>" \
-H "content-length: <message_body_size>"


Response

Element Name Description
collectionType
ownerId
ownerType
subscriberId
subscriptionId
{
"collectionType":"activities",
"ownerId":"GGNJL9",
"ownerType":"user",
"subscriberId":"1",
"subscriptionId":"320"
}
      

Response Headers
content-type The media type of the response content being sent to the client.
Supported: application/json
fitbit-rate-limit-limit The quota number of calls.
fitbit-rate-limit-remaining The number of calls remaining before hitting the rate limit.
fitbit-rate-limit-reset The number of seconds until the rate limit resets.

Note: The rate limit headers are approximate and asynchronously updated. This means that there may be a minor delay in the decrementing of remaining requests. This could result in your application receiving an unexpected 429 response if you don't track the total number of requests you make yourself.

Response Type

HTTP Status Code HTTP response code. List of codes are found in the Troubleshooting Guide.
Status Message Description of the status code.
Response Body Contains the JSON response to the API call. When errors are returned by the API call, the errorType, fieldName and message text will provide more information to the cause of the failure.

Response Codes
200 Returned if the given user is already subscribed to the stream using the same subscription ID.
201 Returned if a new subscription was created in response to your request.
409 Returned if the given user is already subscribed to this stream using a different subscription ID, OR if the given subscription ID is already used to identify a subscription to a different stream.

Conflicts

A single user can only subscribe to the same stream once. If a conflict arises trying to add a subscription, the server will respond with an HTTP 409 Conflict. It will still return the same response elements, but in this case, the body will tell you that the subscription already exists so that corrective action must be taken.

Note: For a complete list of response codes, please refer to the Troubleshooting Guide.

Additional Information

Activity webhook notifications

The Fitbit Web API can send notifications when a Fitbit user has new data to download. This is possible by implementing the Subscription API and subscribing to one or more data collections. See Using Subscriptions. Whenever the activity service recognizes a change to the user’s data, a notification is sent to your application’s subscriber.

The activity collection recognizes changes to a user’s recorded activities, step count, calories burned, distance traveled, etc. Keep in mind that even when a person is not in motion, their body is burning calories. It’s possible to receive activity notifications representing calorie burn even when the user is sleeping or stationary. Today, you cannot subscribe to a subset of the user’s activity data. So, it is the responsibility of your application to query the necessary activity endpoint(s) to reconcile the data in your system.