Google Ads Ad Manager V1 Client - Class ContactServiceClient (0.5.0)

Reference documentation and code samples for the Google Ads Ad Manager V1 Client class ContactServiceClient.

Service Description: Provides methods for handling Contact objects.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Ads \ AdManager \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array|Google\ApiCore\Options\ClientOptions

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials FetchAuthTokenInterface|CredentialsWrapper

This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Ads\AdManager\V1\ContactServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new ContactServiceClient(['credentials' => $creds]); https://cloud.google.com/docs/authentication/external/externally-sourced-credentials

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. At the moment, supports only rest. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'rest' => [...], ]; See the Google\ApiCore\Transport\RestTransport::build() method for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

↳ logger false|LoggerInterface

A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag

↳ universeDomain string

The service domain for the client. Defaults to 'googleapis.com'.

batchCreateContacts

API to batch create Contact objects.

The async variant is ContactServiceClient::batchCreateContactsAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchCreateContactsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\BatchCreateContactsResponse
Example
use Google\Ads\AdManager\V1\BatchCreateContactsRequest;
use Google\Ads\AdManager\V1\BatchCreateContactsResponse;
use Google\Ads\AdManager\V1\Client\ContactServiceClient;
use Google\Ads\AdManager\V1\Contact;
use Google\Ads\AdManager\V1\CreateContactRequest;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent                 The parent resource where `Contacts` will be created.
 *                                                Format: `networks/{network_code}`
 *                                                The parent field in the CreateContactRequest must match this
 *                                                field. Please see
 *                                                {@see ContactServiceClient::networkName()} for help formatting this field.
 * @param string $formattedRequestsParent         The parent resource where this `Contact` will be created.
 *                                                Format: `networks/{network_code}`
 *                                                Please see {@see ContactServiceClient::networkName()} for help formatting this field.
 * @param string $requestsContactDisplayName      The name of the contact. This attribute has a maximum length of
 *                                                127 characters.
 * @param string $formattedRequestsContactCompany Immutable. The resource name of the Company.
 *                                                Format: "networks/{network_code}/companies/{company_id}"
 *                                                Please see {@see ContactServiceClient::companyName()} for help formatting this field.
 */
function batch_create_contacts_sample(
    string $formattedParent,
    string $formattedRequestsParent,
    string $requestsContactDisplayName,
    string $formattedRequestsContactCompany
): void {
    // Create a client.
    $contactServiceClient = new ContactServiceClient();

    // Prepare the request message.
    $requestsContact = (new Contact())
        ->setDisplayName($requestsContactDisplayName)
        ->setCompany($formattedRequestsContactCompany);
    $createContactRequest = (new CreateContactRequest())
        ->setParent($formattedRequestsParent)
        ->setContact($requestsContact);
    $requests = [$createContactRequest,];
    $request = (new BatchCreateContactsRequest())
        ->setParent($formattedParent)
        ->setRequests($requests);

    // Call the API and handle any network failures.
    try {
        /** @var BatchCreateContactsResponse $response */
        $response = $contactServiceClient->batchCreateContacts($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ContactServiceClient::networkName('[NETWORK_CODE]');
    $formattedRequestsParent = ContactServiceClient::networkName('[NETWORK_CODE]');
    $requestsContactDisplayName = '[DISPLAY_NAME]';
    $formattedRequestsContactCompany = ContactServiceClient::companyName('[NETWORK_CODE]', '[COMPANY]');

    batch_create_contacts_sample(
        $formattedParent,
        $formattedRequestsParent,
        $requestsContactDisplayName,
        $formattedRequestsContactCompany
    );
}

batchUpdateContacts

API to batch update Contact objects.

The async variant is ContactServiceClient::batchUpdateContactsAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchUpdateContactsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\BatchUpdateContactsResponse
Example
use Google\Ads\AdManager\V1\BatchUpdateContactsRequest;
use Google\Ads\AdManager\V1\BatchUpdateContactsResponse;
use Google\Ads\AdManager\V1\Client\ContactServiceClient;
use Google\Ads\AdManager\V1\Contact;
use Google\Ads\AdManager\V1\UpdateContactRequest;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * @param string $formattedParent                 The parent resource where `Contacts` will be updated.
 *                                                Format: `networks/{network_code}`
 *                                                The parent field in the UpdateContactRequest must match this
 *                                                field. Please see
 *                                                {@see ContactServiceClient::networkName()} for help formatting this field.
 * @param string $requestsContactDisplayName      The name of the contact. This attribute has a maximum length of
 *                                                127 characters.
 * @param string $formattedRequestsContactCompany Immutable. The resource name of the Company.
 *                                                Format: "networks/{network_code}/companies/{company_id}"
 *                                                Please see {@see ContactServiceClient::companyName()} for help formatting this field.
 */
function batch_update_contacts_sample(
    string $formattedParent,
    string $requestsContactDisplayName,
    string $formattedRequestsContactCompany
): void {
    // Create a client.
    $contactServiceClient = new ContactServiceClient();

    // Prepare the request message.
    $requestsContact = (new Contact())
        ->setDisplayName($requestsContactDisplayName)
        ->setCompany($formattedRequestsContactCompany);
    $requestsUpdateMask = new FieldMask();
    $updateContactRequest = (new UpdateContactRequest())
        ->setContact($requestsContact)
        ->setUpdateMask($requestsUpdateMask);
    $requests = [$updateContactRequest,];
    $request = (new BatchUpdateContactsRequest())
        ->setParent($formattedParent)
        ->setRequests($requests);

    // Call the API and handle any network failures.
    try {
        /** @var BatchUpdateContactsResponse $response */
        $response = $contactServiceClient->batchUpdateContacts($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ContactServiceClient::networkName('[NETWORK_CODE]');
    $requestsContactDisplayName = '[DISPLAY_NAME]';
    $formattedRequestsContactCompany = ContactServiceClient::companyName('[NETWORK_CODE]', '[COMPANY]');

    batch_update_contacts_sample(
        $formattedParent,
        $requestsContactDisplayName,
        $formattedRequestsContactCompany
    );
}

createContact

API to create a Contact object.

The async variant is ContactServiceClient::createContactAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\CreateContactRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\Contact
Example
use Google\Ads\AdManager\V1\Client\ContactServiceClient;
use Google\Ads\AdManager\V1\Contact;
use Google\Ads\AdManager\V1\CreateContactRequest;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent         The parent resource where this `Contact` will be created.
 *                                        Format: `networks/{network_code}`
 *                                        Please see {@see ContactServiceClient::networkName()} for help formatting this field.
 * @param string $contactDisplayName      The name of the contact. This attribute has a maximum length of
 *                                        127 characters.
 * @param string $formattedContactCompany Immutable. The resource name of the Company.
 *                                        Format: "networks/{network_code}/companies/{company_id}"
 *                                        Please see {@see ContactServiceClient::companyName()} for help formatting this field.
 */
function create_contact_sample(
    string $formattedParent,
    string $contactDisplayName,
    string $formattedContactCompany
): void {
    // Create a client.
    $contactServiceClient = new ContactServiceClient();

    // Prepare the request message.
    $contact = (new Contact())
        ->setDisplayName($contactDisplayName)
        ->setCompany($formattedContactCompany);
    $request = (new CreateContactRequest())
        ->setParent($formattedParent)
        ->setContact($contact);

    // Call the API and handle any network failures.
    try {
        /** @var Contact $response */
        $response = $contactServiceClient->createContact($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ContactServiceClient::networkName('[NETWORK_CODE]');
    $contactDisplayName = '[DISPLAY_NAME]';
    $formattedContactCompany = ContactServiceClient::companyName('[NETWORK_CODE]', '[COMPANY]');

    create_contact_sample($formattedParent, $contactDisplayName, $formattedContactCompany);
}

getContact

API to retrieve a Contact object.

The async variant is ContactServiceClient::getContactAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\GetContactRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\Contact
Example
use Google\Ads\AdManager\V1\Client\ContactServiceClient;
use Google\Ads\AdManager\V1\Contact;
use Google\Ads\AdManager\V1\GetContactRequest;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The resource name of the Contact.
 *                              Format: `networks/{network_code}/contacts/{contact_id}`
 *                              Please see {@see ContactServiceClient::contactName()} for help formatting this field.
 */
function get_contact_sample(string $formattedName): void
{
    // Create a client.
    $contactServiceClient = new ContactServiceClient();

    // Prepare the request message.
    $request = (new GetContactRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Contact $response */
        $response = $contactServiceClient->getContact($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ContactServiceClient::contactName('[NETWORK_CODE]', '[CONTACT]');

    get_contact_sample($formattedName);
}

listContacts

API to retrieve a list of Contact objects.

The async variant is ContactServiceClient::listContactsAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\ListContactsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\Ads\AdManager\V1\Client\ContactServiceClient;
use Google\Ads\AdManager\V1\ListContactsRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent The parent, which owns this collection of Contacts.
 *                                Format: `networks/{network_code}`
 *                                Please see {@see ContactServiceClient::networkName()} for help formatting this field.
 */
function list_contacts_sample(string $formattedParent): void
{
    // Create a client.
    $contactServiceClient = new ContactServiceClient();

    // Prepare the request message.
    $request = (new ListContactsRequest())
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $contactServiceClient->listContacts($request);

        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ContactServiceClient::networkName('[NETWORK_CODE]');

    list_contacts_sample($formattedParent);
}

updateContact

API to update a Contact object.

The async variant is ContactServiceClient::updateContactAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\UpdateContactRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\Contact
Example
use Google\Ads\AdManager\V1\Client\ContactServiceClient;
use Google\Ads\AdManager\V1\Contact;
use Google\Ads\AdManager\V1\UpdateContactRequest;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * @param string $contactDisplayName      The name of the contact. This attribute has a maximum length of
 *                                        127 characters.
 * @param string $formattedContactCompany Immutable. The resource name of the Company.
 *                                        Format: "networks/{network_code}/companies/{company_id}"
 *                                        Please see {@see ContactServiceClient::companyName()} for help formatting this field.
 */
function update_contact_sample(string $contactDisplayName, string $formattedContactCompany): void
{
    // Create a client.
    $contactServiceClient = new ContactServiceClient();

    // Prepare the request message.
    $contact = (new Contact())
        ->setDisplayName($contactDisplayName)
        ->setCompany($formattedContactCompany);
    $updateMask = new FieldMask();
    $request = (new UpdateContactRequest())
        ->setContact($contact)
        ->setUpdateMask($updateMask);

    // Call the API and handle any network failures.
    try {
        /** @var Contact $response */
        $response = $contactServiceClient->updateContact($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $contactDisplayName = '[DISPLAY_NAME]';
    $formattedContactCompany = ContactServiceClient::companyName('[NETWORK_CODE]', '[COMPANY]');

    update_contact_sample($contactDisplayName, $formattedContactCompany);
}

batchCreateContactsAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchCreateContactsRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\BatchCreateContactsResponse>

batchUpdateContactsAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchUpdateContactsRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\BatchUpdateContactsResponse>

createContactAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\CreateContactRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\Contact>

getContactAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\GetContactRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\Contact>

listContactsAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\ListContactsRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

updateContactAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\UpdateContactRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\Contact>

static::companyName

Formats a string containing the fully-qualified path to represent a company resource.

Parameters
Name Description
networkCode string
company string
Returns
Type Description
string The formatted company resource.

static::contactName

Formats a string containing the fully-qualified path to represent a contact resource.

Parameters
Name Description
networkCode string
contact string
Returns
Type Description
string The formatted contact resource.

static::networkName

Formats a string containing the fully-qualified path to represent a network resource.

Parameter
Name Description
networkCode string
Returns
Type Description
string The formatted network resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • company: networks/{network_code}/companies/{company}
  • contact: networks/{network_code}/contacts/{contact}
  • network: networks/{network_code}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template ?string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.