Google Cloud Essential Contacts V1 Client - Class EssentialContactsServiceClient (0.4.5)

Reference documentation and code samples for the Google Cloud Essential Contacts V1 Client class EssentialContactsServiceClient.

Service Description: Manages contacts for important Google Cloud notifications.

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 \ Cloud \ EssentialContacts \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array

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 string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ 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. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. 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 = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods 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.

computeContacts

Lists all contacts for the resource that are subscribed to the specified notification categories, including contacts inherited from any parent resources.

The async variant is Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient::computeContactsAsync() .

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\ComputeContactsRequest

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\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\ComputeContactsRequest;
use Google\Cloud\EssentialContacts\V1\Contact;

/**
 * @param string $formattedParent The name of the resource to compute contacts for.
 *                                Format: organizations/{organization_id},
 *                                folders/{folder_id} or projects/{project_id}
 *                                Please see {@see EssentialContactsServiceClient::projectName()} for help formatting this field.
 */
function compute_contacts_sample(string $formattedParent): void
{
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

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

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

        /** @var Contact $element */
        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 = EssentialContactsServiceClient::projectName('[PROJECT]');

    compute_contacts_sample($formattedParent);
}

createContact

Parameters
Name Description
request Google\Cloud\EssentialContacts\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\Cloud\EssentialContacts\V1\Contact
Example
use Google\ApiCore\ApiException;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\Contact;
use Google\Cloud\EssentialContacts\V1\CreateContactRequest;
use Google\Cloud\EssentialContacts\V1\NotificationCategory;

/**
 * @param string $formattedParent                                 The resource to save this contact for.
 *                                                                Format: organizations/{organization_id}, folders/{folder_id} or
 *                                                                projects/{project_id}
 *                                                                Please see {@see EssentialContactsServiceClient::projectName()} for help formatting this field.
 * @param string $contactEmail                                    The email address to send notifications to. The email address
 *                                                                does not need to be a Google Account.
 * @param int    $contactNotificationCategorySubscriptionsElement The categories of notifications that the contact will receive
 *                                                                communications for.
 * @param string $contactLanguageTag                              The preferred language for notifications, as a ISO 639-1 language
 *                                                                code. See [Supported
 *                                                                languages](https://cloud.google.com/resource-manager/docs/managing-notification-contacts#supported-languages)
 *                                                                for a list of supported languages.
 */
function create_contact_sample(
    string $formattedParent,
    string $contactEmail,
    int $contactNotificationCategorySubscriptionsElement,
    string $contactLanguageTag
): void {
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

    // Prepare the request message.
    $contactNotificationCategorySubscriptions = [$contactNotificationCategorySubscriptionsElement,];
    $contact = (new Contact())
        ->setEmail($contactEmail)
        ->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions)
        ->setLanguageTag($contactLanguageTag);
    $request = (new CreateContactRequest())
        ->setParent($formattedParent)
        ->setContact($contact);

    // Call the API and handle any network failures.
    try {
        /** @var Contact $response */
        $response = $essentialContactsServiceClient->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 = EssentialContactsServiceClient::projectName('[PROJECT]');
    $contactEmail = '[EMAIL]';
    $contactNotificationCategorySubscriptionsElement = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED;
    $contactLanguageTag = '[LANGUAGE_TAG]';

    create_contact_sample(
        $formattedParent,
        $contactEmail,
        $contactNotificationCategorySubscriptionsElement,
        $contactLanguageTag
    );
}

deleteContact

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\DeleteContactRequest

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.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\DeleteContactRequest;

/**
 * @param string $formattedName The name of the contact to delete.
 *                              Format: organizations/{organization_id}/contacts/{contact_id},
 *                              folders/{folder_id}/contacts/{contact_id} or
 *                              projects/{project_id}/contacts/{contact_id}
 *                              Please see {@see EssentialContactsServiceClient::contactName()} for help formatting this field.
 */
function delete_contact_sample(string $formattedName): void
{
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

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

    // Call the API and handle any network failures.
    try {
        $essentialContactsServiceClient->deleteContact($request);
        printf('Call completed successfully.' . PHP_EOL);
    } 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 = EssentialContactsServiceClient::contactName('[PROJECT]', '[CONTACT]');

    delete_contact_sample($formattedName);
}

getContact

Parameters
Name Description
request Google\Cloud\EssentialContacts\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\Cloud\EssentialContacts\V1\Contact
Example
use Google\ApiCore\ApiException;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\Contact;
use Google\Cloud\EssentialContacts\V1\GetContactRequest;

/**
 * @param string $formattedName The name of the contact to retrieve.
 *                              Format: organizations/{organization_id}/contacts/{contact_id},
 *                              folders/{folder_id}/contacts/{contact_id} or
 *                              projects/{project_id}/contacts/{contact_id}
 *                              Please see {@see EssentialContactsServiceClient::contactName()} for help formatting this field.
 */
function get_contact_sample(string $formattedName): void
{
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

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

    // Call the API and handle any network failures.
    try {
        /** @var Contact $response */
        $response = $essentialContactsServiceClient->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 = EssentialContactsServiceClient::contactName('[PROJECT]', '[CONTACT]');

    get_contact_sample($formattedName);
}

listContacts

Lists the contacts that have been set on a resource.

The async variant is Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient::listContactsAsync() .

Parameters
Name Description
request Google\Cloud\EssentialContacts\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\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\Contact;
use Google\Cloud\EssentialContacts\V1\ListContactsRequest;

/**
 * @param string $formattedParent The parent resource name.
 *                                Format: organizations/{organization_id}, folders/{folder_id} or
 *                                projects/{project_id}
 *                                Please see {@see EssentialContactsServiceClient::projectName()} for help formatting this field.
 */
function list_contacts_sample(string $formattedParent): void
{
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

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

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

        /** @var Contact $element */
        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 = EssentialContactsServiceClient::projectName('[PROJECT]');

    list_contacts_sample($formattedParent);
}

sendTestMessage

Allows a contact admin to send a test message to contact to verify that it has been configured correctly.

The async variant is Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient::sendTestMessageAsync() .

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\SendTestMessageRequest

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.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\NotificationCategory;
use Google\Cloud\EssentialContacts\V1\SendTestMessageRequest;

/**
 * @param string $formattedContactsElement The list of names of the contacts to send a test message to.
 *                                         Format: organizations/{organization_id}/contacts/{contact_id},
 *                                         folders/{folder_id}/contacts/{contact_id} or
 *                                         projects/{project_id}/contacts/{contact_id}
 *                                         Please see {@see EssentialContactsServiceClient::contactName()} for help formatting this field.
 * @param string $formattedResource        The name of the resource to send the test message for. All
 *                                         contacts must either be set directly on this resource or inherited from
 *                                         another resource that is an ancestor of this one. Format:
 *                                         organizations/{organization_id}, folders/{folder_id} or
 *                                         projects/{project_id}
 *                                         Please see {@see EssentialContactsServiceClient::projectName()} for help formatting this field.
 * @param int    $notificationCategory     The notification category to send the test message for. All
 *                                         contacts must be subscribed to this category.
 */
function send_test_message_sample(
    string $formattedContactsElement,
    string $formattedResource,
    int $notificationCategory
): void {
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

    // Prepare the request message.
    $formattedContacts = [$formattedContactsElement,];
    $request = (new SendTestMessageRequest())
        ->setContacts($formattedContacts)
        ->setResource($formattedResource)
        ->setNotificationCategory($notificationCategory);

    // Call the API and handle any network failures.
    try {
        $essentialContactsServiceClient->sendTestMessage($request);
        printf('Call completed successfully.' . PHP_EOL);
    } 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
{
    $formattedContactsElement = EssentialContactsServiceClient::contactName('[PROJECT]', '[CONTACT]');
    $formattedResource = EssentialContactsServiceClient::projectName('[PROJECT]');
    $notificationCategory = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED;

    send_test_message_sample($formattedContactsElement, $formattedResource, $notificationCategory);
}

updateContact

Updates a contact.

Note: A contact's email address cannot be changed.

The async variant is Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient::updateContactAsync() .

Parameters
Name Description
request Google\Cloud\EssentialContacts\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\Cloud\EssentialContacts\V1\Contact
Example
use Google\ApiCore\ApiException;
use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient;
use Google\Cloud\EssentialContacts\V1\Contact;
use Google\Cloud\EssentialContacts\V1\NotificationCategory;
use Google\Cloud\EssentialContacts\V1\UpdateContactRequest;

/**
 * @param string $contactEmail                                    The email address to send notifications to. The email address
 *                                                                does not need to be a Google Account.
 * @param int    $contactNotificationCategorySubscriptionsElement The categories of notifications that the contact will receive
 *                                                                communications for.
 * @param string $contactLanguageTag                              The preferred language for notifications, as a ISO 639-1 language
 *                                                                code. See [Supported
 *                                                                languages](https://cloud.google.com/resource-manager/docs/managing-notification-contacts#supported-languages)
 *                                                                for a list of supported languages.
 */
function update_contact_sample(
    string $contactEmail,
    int $contactNotificationCategorySubscriptionsElement,
    string $contactLanguageTag
): void {
    // Create a client.
    $essentialContactsServiceClient = new EssentialContactsServiceClient();

    // Prepare the request message.
    $contactNotificationCategorySubscriptions = [$contactNotificationCategorySubscriptionsElement,];
    $contact = (new Contact())
        ->setEmail($contactEmail)
        ->setNotificationCategorySubscriptions($contactNotificationCategorySubscriptions)
        ->setLanguageTag($contactLanguageTag);
    $request = (new UpdateContactRequest())
        ->setContact($contact);

    // Call the API and handle any network failures.
    try {
        /** @var Contact $response */
        $response = $essentialContactsServiceClient->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
{
    $contactEmail = '[EMAIL]';
    $contactNotificationCategorySubscriptionsElement = NotificationCategory::NOTIFICATION_CATEGORY_UNSPECIFIED;
    $contactLanguageTag = '[LANGUAGE_TAG]';

    update_contact_sample(
        $contactEmail,
        $contactNotificationCategorySubscriptionsElement,
        $contactLanguageTag
    );
}

computeContactsAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\ComputeContactsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

createContactAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\CreateContactRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteContactAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\DeleteContactRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getContactAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\GetContactRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listContactsAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\ListContactsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

sendTestMessageAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\SendTestMessageRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateContactAsync

Parameters
Name Description
request Google\Cloud\EssentialContacts\V1\UpdateContactRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

static::contactName

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

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

static::folderName

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

Parameter
Name Description
folder string
Returns
Type Description
string The formatted folder resource.

static::folderContactName

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

Parameters
Name Description
folder string
contact string
Returns
Type Description
string The formatted folder_contact resource.

static::organizationName

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

Parameter
Name Description
organization string
Returns
Type Description
string The formatted organization resource.

static::organizationContactName

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

Parameters
Name Description
organization string
contact string
Returns
Type Description
string The formatted organization_contact resource.

static::projectName

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

Parameter
Name Description
project string
Returns
Type Description
string The formatted project resource.

static::projectContactName

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

Parameters
Name Description
project string
contact string
Returns
Type Description
string The formatted project_contact 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

  • contact: projects/{project}/contacts/{contact}
  • folder: folders/{folder}
  • folderContact: folders/{folder}/contacts/{contact}
  • organization: organizations/{organization}
  • organizationContact: organizations/{organization}/contacts/{contact}
  • project: projects/{project}
  • projectContact: projects/{project}/contacts/{contact}

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.