Search code examples
postgoogle-apigoogle-drive-apiwebhookshttp-status-code-400

"Required parameter: pageToken" error when attempting to register Google Drive webhooks


Following the guide here, I'm trying to set up Google Drive "push notifications" (webhooks) so I can watch for all file changes. I need to send a one-off POST request to https://www.googleapis.com/drive/v3/changes/watch to initially "register" the webhook. But I cannot seem to do this successfully; using curl I receive a 400 Bad Request response.

Here's my HTTP request via curl:

curl 'https://www.googleapis.com/drive/v3/changes/watch' \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer access_token' \
--data-binary '{"id": "webhook", "type": "web_hook", "address": "https://example.com/webhooks", "token": "example"}' \
-vvvv

The response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required parameter: pageToken",
    "locationType": "parameter",
    "location": "pageToken"
   }
  ],
  "code": 400,
  "message": "Required parameter: pageToken"
 }
}

What is the pageToken and where do I get it? Also, how do I include it in the request (e.g. as a header)? There's nothing mentioned in the guide about it.


Solution

  • Directly from the documentation

    Changes: watch Subscribes to changes for a user.
    Required query parameters
    pageToken string

    The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response or to the response from the getStartPageToken method.

    If this is the first request then you will need to use the getStartPageToken method to get the first token then there after the page token will be part of the response.