Aarish Ramesh
Aarish Ramesh

Reputation: 7043

Google drive webhook notifications request body is null

I have integrated google drive into my application. To achieve sync, I have also configured push notifications for each account by following the steps in the link https://developers.google.com/drive/v3/web/push

Below is the java code to configure watch on all files for the account

String uuid = UUID.randomUUID().toString(); 
                Channel channel = new Channel(); 
                channel.setId(uuid);
                channel.setType("web_hook");
                channel.setAddress(env.getProperty("webhookUrl"));
                StartPageToken pageToken = service.changes().getStartPageToken().execute();
                Channel response = service.changes().watch(pageToken.getStartPageToken(), channel).execute();

On making changes in the actual google drive, I get the notification in the webhook url configured above.

But the problem is for every change, I am getting the same values for below headers which are same as the response of the watch call & I am not getting any proper request headers corresponding to the change or request body

//Getting request headers
    String resourceId = request.getHeader("X-Goog-Resource-ID");
    String resourceState = request.getHeader("X-Goog-Resource-State");
    String expiration = request.getHeader("X-Goog-Channel-Expiration");
    String resourceChanges = request.getHeader("X-Goog-Changed");
    String channelId = request.getHeader("X-Goog-Channel-ID");

Can someone please let me know how do i get notification data correctly ? Is there anything I am doing wrong ?

Here is the same problem stated by another question which does not have proper answer yet Receiving Google Drive Push Notifications

Upvotes: 1

Views: 1113

Answers (3)

Mukundhan
Mukundhan

Reputation: 3477

Drive provides the following details in the request header.

We can use these info to fetch the file or make any appropriate application changes.

enter image description here

Upvotes: 0

Aarish Ramesh
Aarish Ramesh

Reputation: 7043

Actually there is no request body which gets sent in the webhook notification. So as soon as changes arrive in the callback url, changes are to be fetched by making a get request to changes resource uri

Resource URI : https://www.googleapis.com/drive/v3/changes?includeRemoved=true&pageSize=100&pageToken=895&restrictToMyDrive=false&spaces=drive&alt=json

Or programatically changes can be fetched by using the below code

String pageToken = channelInfo.getCurrPageToken();
            List<Change> changes = service.changes().list(pageToken)
                    .execute().getChanges();

Google push notifications doc could have mentioned this clearly rather than mentioning that the changes come along in the request body which is the reason for confusion

Upvotes: 7

pinoyyid
pinoyyid

Reputation: 22306

I don't understand why you are looking at the headers of the webhook message. It is the body that you are interested in as described at https://developers.google.com/drive/v3/reference/files/watch.

Once you have the ID of the changed file, if you want details of what has changed, you can use the Revisions https://developers.google.com/drive/v3/web/manage-revisions feed to see the details.

Upvotes: 1

Related Questions