0

I´m trying to update existing contact using People service from Google apps gs. I have a contact like this:

let contactInfo = {
  "name" : "Jhon",
  "lastName": "Doe",
  "phone": "+1999999",
  "rn": "people/c8289118840931811524",
  "etag": "%EgkBAj0JPgs/Ny4aBAECBQciDDV1TzVFdXY0ckhnPQ=="
}

I created the folowing function in order to update contact more easily:

function updateContact(contactInfo){
  //var updatePersonFields = "updatePersonFields=names,phoneNumbers,emailAddresses";
  var bodyRequest = {
    "resourceName": contactInfo.rn,
    "etag": contactInfo.etag,
    "names": [{
      "givenName": contactInfo.name,
      "familyName": contactInfo.lastName,
    }],
    "phoneNumbers": [{
      'value': contactInfo.phone
    }],
    "emailAddresses": [{
      'value': contactInfo.email
    }]
  };

  People.People.updateContact(bodyRequest, contactInfo.rn);
}

However, the document guide for updateContact needs 3 parameters: Path parameters, Query Parameters and request body: https://developers.google.com/people/api/rest/v1/people/updateContact

In order to update contact, I have to pass updatePersonfields, but it is a Query Parameter and the updateContact just only receive 2 parameters.

I know that etag and updatePersonfields is needed, as the link explain it: https://developers.google.com/people/v1/contacts?hl=en#update_an_existing_contact

How can I add the Query Parameter updatePersonFields (in comments)?

If updatePersonField is not send it, I have the following error:

GoogleJsonResponseException: API call to people.people.updateContact failed with error:
updatePersonFields mask is required. Please specify one or more valid paths.
Valid paths are documented at
https://developers.google.com/people/api/rest/v1/people/updateContact.

Thanks you in advanced.

Omar F.
  • 27
  • 5

1 Answers1

1

In your situation, please include updatePersonFields to 3rd argument of People.People.updateContact as an object.

In this case, when you use People API of Advanced Google services with the script editor of Google Apps Script, you can see the document of updateContact(resource: Peopleapi_v1.Peopleapi.V1.Schema.Person, resourceName: string, optionalArgs: Object) by the auto-completion of script editor.

So, when your script is modified, it becomes as follows.

From:

People.People.updateContact(bodyRequest, contactInfo.rn);

To:

People.People.updateContact(bodyRequest, contactInfo.rn, {updatePersonFields: "emailAddresses,names,phoneNumbers"});

Note:

  • When your bodyRequest is invalid value, an error occurs. Please be careful this.

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Inside the paremeter with the shorcuts CTRL+SHIF+SPACE I can see the two overloaded methods. thanks. – Omar F. Jun 16 '21 at 02:53