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

Creating subscriber in new Google Health API fails with 403

ANSWERED

Hi!

I'm trying to create a subscriber with the following request:

POST https://health.googleapis.com/v4/projects/brp-coach-dev/subscribers?subscriberId=google-health-subsc...

Body:

{
"endpointUri": "MY_WEBHOOK_URL",
"subscriberConfigs": [
{
"dataTypes": ["steps", "weight"],
"subscriptionCreatePolicy": "AUTOMATIC"
}
],
"endpointAuthorization": {
"secret": "Bearer XXX"
}
}

Response:

{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}

When testing my access token (https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=XXX) I have the correct scopes:

"scope": "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/googlehealth.activity_and_fitness.readonly https://www.googleapis.com/auth/googlehealth.health_metrics_and_measurements.readonly",

This endpoit is suppose to require the https://www.googleapis.com/auth/cloud-platform scope that I have, my user is also owner of the project.

Is this a bug or what am I doing wrong?

best regards
Alexander

Best Answer
1 BEST ANSWER

Accepted Solutions

Hi @shapelink 

Thank you for your patience.  In the create subscriber endpoint, you need to use the project id instead of the project name in the URL.   For example, here is the syntax I used to create a subscriber.

POST {{google_health_v4_host}}/projects/6183080339/subscribers?subscriberId=webhooks
Authorization: Bearer {{access_token}}
Accept: application/json

{
  "endpointUri": "<endpoint-URL>",
  "subscriberConfigs": [
    {
      "dataTypes": [
        "steps", "weight", "sleep"
      ],
      "subscriptionCreatePolicy": "AUTOMATIC"
    }
  ],
  "endpointAuthorization" : {
    "secret": "Bearer 618308034039-au5r1vjbnic6pp.apps.googleusercontent.com"
  }
}

I'm working on some instructions to put in the documentation to help with creating a subscriber.  Let me know what happens after changing the project name to project id.

View best answer in original post

Best Answer
6 REPLIES 6

@shapelink any update? Were you able to resolve?

Best Answer
0 Votes

No, I have not been able to create a subscriber. I have tested with acess tokens created from both oauth flow and service account.

Best Answer
0 Votes

@GordonFitbit can you have a look at this?

Best Answer
0 Votes

Hi @shapelink 

Welcome to the community. 

We are currently investigating the issue. I will share more details once I have any updates. Thanks!

Best Answer
0 Votes

Hi @shapelink 

Thank you for your patience.  In the create subscriber endpoint, you need to use the project id instead of the project name in the URL.   For example, here is the syntax I used to create a subscriber.

POST {{google_health_v4_host}}/projects/6183080339/subscribers?subscriberId=webhooks
Authorization: Bearer {{access_token}}
Accept: application/json

{
  "endpointUri": "<endpoint-URL>",
  "subscriberConfigs": [
    {
      "dataTypes": [
        "steps", "weight", "sleep"
      ],
      "subscriptionCreatePolicy": "AUTOMATIC"
    }
  ],
  "endpointAuthorization" : {
    "secret": "Bearer 618308034039-au5r1vjbnic6pp.apps.googleusercontent.com"
  }
}

I'm working on some instructions to put in the documentation to help with creating a subscriber.  Let me know what happens after changing the project name to project id.

Best Answer

Replacing the project ID with the project NUMBER worked! It would probably be good to update the documentation and specify that it is the project number that should be used. 

Thanks!

Best Answer
0 Votes