Search code examples
google-apps-scriptcontacts

Add/set Department name to contact


How to add or set value for "Department" field in google contacts? No problems with "Company" and "Job title"

var contact = ContactsApp.createContact('John', 'Doe', '[email protected]');
var company_set = contact.addCompany('Google', 'Product Manager');
// ?????
var department_set = contact.add______________('IT');

UPD: Thanks to @TheMaster I've managed to solve this task. Nice API example you can find here https://www.any-api.com/googleapis_com/people/docs/people/people_people_createContact Using the examle on this site you can build required body for API.

  var reqBody = { 
    names: [
      { 
        givenName: givenName, 
        familyName: familyName 
      }
    ],
    phoneNumbers: phoneNumbers,
    organizations: [
      {
        title: orgTitle,
        department: orgDepartment
      }
    ],
    emailAddresses: [
      {
        value: emailAddres,
        type: 'work'
      }
    ],
    addresses: [
      {
        city: city,
        streetAddress: streetAddress,
        type: 'work'
      }
    ],
    memberships:  [
      {

        contactGroupMembership: {
          contactGroupId: contactGroupsID,
          contactGroupResourceName: "contactGroups/" + contactGroupsID
        }
      }
    ]
  }

createContact(reqBody);

Solution

  • It is possible to set department through People API with Advanced Google services. When a contact is created through the api, the people object can include organizations[].department