Skip to main content

subscriptions

Creates, updates, deletes, gets or lists a subscriptions resource.

Overview

Namesubscriptions
TypeResource
Idgoogle.health.subscriptions

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
namestringIdentifier. The resource name of the Subscription. Format: projects/{project}/subscribers/{subscriber}/subscriptions/{subscription} Example: projects/my-project/subscribers/my-subscriber-123/subscriptions/my-subscription-456 The {project} ID is mandatory (6-30 characters, matching /a-z{6,30}/) The {subscriber} ID is user-settable (4-36 characters, matching /a-z/) if provided during creation, or system-generated otherwise. The {subscription} ID is user-settable (4-36 chars, matching /a-z/) or system-generated otherwise.
dataTypesarrayOptional. Data types subscribed to. A subscriber will only receive notifications for data types that are declared here. A subscription can only subscribe to the data types of the subscriber. The values should be in the format "users/{health_user_id}/dataTypes/{data_type}" where {data_type} is one of "altitude", "distance", "floors", "sleep", "steps", "weight".
userstringImmutable. The resource name of the user for whom this subscription is active. Format: users/{user} where {user} is the public healthUserId as returned by the GetIdentity action in the profile PAPI (see google.devicesandservices.health.v4main.HealthProfileService.GetIdentity).

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectprojectsId, subscribersIdfilter, pageSize, pageTokenLists all active subscriptions for a given subscriber. This can be filtered, for example, by user or data type.
createinsertprojectsId, subscribersIdsubscriptionIdCreates a subscription for a specific user to a specific subscriber. This method requires the subscriber to have a SubscriptionCreatePolicy set to MANUAL for the given data types.
patchupdateprojectsId, subscribersId, subscriptionsIdupdateMaskUpdates the data types for an existing user subscription.
deletedeleteprojectsId, subscribersId, subscriptionsIdDeletes a specific user subscription, stopping notifications for this user to this subscriber.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
projectsIdstring
subscribersIdstring
subscriptionsIdstring
filterstring
pageSizeinteger (int32)
pageTokenstring
subscriptionIdstring
updateMaskstring (google-fieldmask)

SELECT examples

Lists all active subscriptions for a given subscriber. This can be filtered, for example, by user or data type.

SELECT
name,
dataTypes,
user
FROM google.health.subscriptions
WHERE projectsId = '{{ projectsId }}' -- required
AND subscribersId = '{{ subscribersId }}' -- required
AND filter = '{{ filter }}'
AND pageSize = '{{ pageSize }}'
AND pageToken = '{{ pageToken }}'
;

INSERT examples

Creates a subscription for a specific user to a specific subscriber. This method requires the subscriber to have a SubscriptionCreatePolicy set to MANUAL for the given data types.

INSERT INTO google.health.subscriptions (
data__dataTypes,
data__user,
projectsId,
subscribersId,
subscriptionId
)
SELECT
'{{ dataTypes }}',
'{{ user }}',
'{{ projectsId }}',
'{{ subscribersId }}',
'{{ subscriptionId }}'
RETURNING
name,
dataTypes,
user
;

UPDATE examples

Updates the data types for an existing user subscription.

UPDATE google.health.subscriptions
SET
data__dataTypes = '{{ dataTypes }}',
data__user = '{{ user }}',
data__name = '{{ name }}'
WHERE
projectsId = '{{ projectsId }}' --required
AND subscribersId = '{{ subscribersId }}' --required
AND subscriptionsId = '{{ subscriptionsId }}' --required
AND updateMask = '{{ updateMask}}'
RETURNING
name,
dataTypes,
user;

DELETE examples

Deletes a specific user subscription, stopping notifications for this user to this subscriber.

DELETE FROM google.health.subscriptions
WHERE projectsId = '{{ projectsId }}' --required
AND subscribersId = '{{ subscribersId }}' --required
AND subscriptionsId = '{{ subscriptionsId }}' --required
;