0
votes

I use Google people API to update a contact.

I save the resourceName of the created contact and when I update the contact, I just use this code

People.People.updateContact({"emailAddresses": [{
                "type": "work",
                "value": "[email protected]"
            }]}, "people/c6679930577989153852")

But this throws error - GoogleJsonResponseException: API call to people.people.updateContact failed with error: Request must set person.etag or person.metadata.sources.etag for the source that is being updated.

How do I create an etag if I dont store the created etag at the time of contact creation? Is there a way I can create a new etag using a function so I can force update the entire contact?

if so how do I create a updatePersonFields mask?

1
How did this work out for you?iansedano

1 Answers

0
votes

How to deal with the etag Contacts API error.

The server returns a 400 error with reason "failedPrecondition" if person.metadata.sources.etag is different than the contact's etag, which indicates the contact has changed since its data was read. Clients should get the latest person and merge their updates into the latest person.

Source

So you are right in thinking that you need the etag to be able to complete the operation you want.

However, generating it is not the right way to go.

You would need to first make a simple get request with any personFields to get the current etag value. Then you would use this etag value in the update.

This is to prevent you from overwriting and duplicating possibly important information.

Reference