Search code examples
phpgoogle-apigoogle-people-api

How to Create new Contact using People API with multiple values


I want to Create New Contact with multiple emails and phone numbers

i have try with one email and phone number it is working this is the code im using


$name = new Google_Service_PeopleService_Name();
$name->setGivenName('00nirman');
$name->setFamilyName('weerasinghe');
$person->setNames($name);
$email1 = new Google_Service_PeopleService_EmailAddress();
$email1->setValue('[email protected]');
$person->setEmailAddresses($email1);

$phone1 = new Google_Service_PeopleService_PhoneNumber();
$phone1->setValue('0777677305');
$phone1->setType('home');
$person->setPhoneNumbers($phone1);
$exe = $people_service->people->createContact($person)->execute;

Can Someone help me to modify the code to push multiple values i have go true lots of google docs but i cannot fine a way to do in php


Solution

  • Parogrock thank you for the answer

    $phone1 = new Google_Service_PeopleService_PhoneNumber();
    $phone2 = new Google_Service_PeopleService_PhoneNumber();
    $phone1->setValue('0777677305');
    $phone2->setValue('0774112128');
    
    $person->setPhoneNumbers([$phone1,$phone2]);
    
    $exe = $people_service->people->createContact($person)->execute;