가입하기

새 클라이언트 계정을 만들려면 미리 채워진 Customer 객체 를 CustomerService에서 CreateCustomerClient 메서드를 사용하여 제출합니다.

mutate 호출을 사용하여 캠페인을 만드는 것과 같은 표준 항목 생성과 달리 생성되는 고객의 ID가 아닌 요청에서 관리자 계정의 고객 ID 를 지정해야 합니다.

요청 및 고객 필드

CustomerService.CreateCustomerClient를 호출할 때 다음 표와 같이 CreateCustomerClientRequest 및 중첩된 Customer 객체를 구성합니다.

필드 또는 헤더 요구사항 변경 가능 여부 및 설명
customer_id 필수 새 고객 계정이 생성되는 직접 상위 관리자 계정 의 10자리 고객 ID (하이픈 제외)
login-customer-id (헤더) 조건부 인증된 사용자가 계층 구조에서 상위의 상위 관리자 계정을 통해 상위 관리자 계정 (customer_id)에 액세스하는 경우 요청 헤더에 필요합니다.
customer_client.descriptive_name 필수 변경 가능: 새 계정의 표시 이름 (예: "Acct Created with CustomerService"). 나중에 CustomerService.MutateCustomer를 사용하여 업데이트할 수 있습니다.
customer_client.currency_code 필수 생성 후 변경 불가능: 3자리 ISO 4217 결제 통화 코드 (예: USD 또는 EUR). 지원되는 통화 코드를 참고하세요.
customer_client.time_zone 필수 생성 후 변경 불가능: 계정 시간대 ID (예: America/New_York). 지원되는 시간대를 참고하세요.
email_address 및 access_role 선택사항 (허용 목록만 해당) 생성 중에 생성된 계정에 사용자 (ADMIN, STANDARD, READ_ONLY 또는 EMAIL_ONLY)를 초대합니다. 허용 목록에 없는 계정은 생성 후 CustomerUserAccessInvitationService를 사용하여 사용자를 초대해야 합니다.
validate_only 선택사항 true인 경우 계정을 만들지 않고 요청 매개변수 및 관리자 자격 요건을 검증합니다.

코드 예

다음 예에서는 기존 관리자 계정에서 고객 계정을 만드는 방법을 보여줍니다.

자바

private void runExample(GoogleAdsClient googleAdsClient, Long managerId) {
  // Formats the current date/time to use as a timestamp in the new customer description.
  String dateTime = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME);

  // Initializes a Customer object to be created.
  Customer customer =
      Customer.newBuilder()
          .setDescriptiveName("Account created with CustomerService on '" + dateTime + "'")
          .setCurrencyCode("USD")
          .setTimeZone("America/New_York")
          // Optional: Sets additional attributes of the customer.
          .setTrackingUrlTemplate("{lpurl}?device={device}")
          .setFinalUrlSuffix("keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}")
          .build();

  // Sends the request to create the customer.
  try (CustomerServiceClient client =
      googleAdsClient.getLatestVersion().createCustomerServiceClient()) {
    CreateCustomerClientResponse response =
        client.createCustomerClient(managerId.toString(), customer);
    System.out.printf(
        "Created a customer with resource name '%s' under the manager account with"
            + " customer ID '%d'.%n",
        response.getResourceName(), managerId);
  }
}
      

C#

public void Run(GoogleAdsClient client, long managerCustomerId)
{
    // Get the CustomerService.
    CustomerServiceClient customerService = client.GetService(Services.V26.CustomerService);

    Customer customer = new Customer()
    {
        DescriptiveName = $"Account created with CustomerService on '{DateTime.Now}'",

        // For a list of valid currency codes and time zones see this documentation:
        // https://developers.google.com/google-ads/api/reference/data/codes-formats#codes_formats.
        CurrencyCode = "USD",
        TimeZone = "America/New_York",

        // The below values are optional. For more information about URL
        // options see: https://support.google.com/google-ads/answer/6305348.
        TrackingUrlTemplate = "{lpurl}?device={device}",
        FinalUrlSuffix = "keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}"
    };

    try
    {
        // Create the account.
        CreateCustomerClientResponse response = customerService.CreateCustomerClient(
            managerCustomerId.ToString(), customer);

        // Display the result.
        Console.WriteLine($"Created a customer with resource name " +
            $"'{response.ResourceName}' under the manager account with customer " +
            $"ID '{managerCustomerId}'");
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

public static function runExample(GoogleAdsClient $googleAdsClient, int $managerCustomerId)
{
    $customer = new Customer([
        'descriptive_name' => 'Account created with CustomerService on ' . date('Ymd h:i:s'),
        // For a list of valid currency codes and time zones see this documentation:
        // https://developers.google.com/google-ads/api/reference/data/codes-formats.
        'currency_code' => 'USD',
        'time_zone' => 'America/New_York',
        // The below values are optional. For more information about URL
        // options see: https://support.google.com/google-ads/answer/6305348.
        'tracking_url_template' => '{lpurl}?device={device}',
        'final_url_suffix' => 'keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}'
    ]);

    // Issues a mutate request to create an account
    $customerServiceClient = $googleAdsClient->getCustomerServiceClient();
    $response = $customerServiceClient->createCustomerClient(
        CreateCustomerClientRequest::build($managerCustomerId, $customer)
    );

    printf(
        'Created a customer with resource name "%s" under the manager account with '
        . 'customer ID %d.%s',
        $response->getResourceName(),
        $managerCustomerId,
        PHP_EOL
    );
}
      

Python

def main(client: GoogleAdsClient, manager_customer_id: str) -> None:
    """The main method that creates all necessary entities for the example.

    Args:
        client: an initialized GoogleAdsClient instance.
        manager_customer_id: a manager client customer ID.
    """
    customer_service: CustomerServiceClient = client.get_service(
        "CustomerService"
    )
    customer: Customer = client.get_type("Customer")
    now: str = datetime.today().strftime("%Y%m%d %H:%M:%S")
    customer.descriptive_name = f"Account created with CustomerService on {now}"
    # For a list of valid currency codes and time zones see this documentation:
    # https://developers.google.com/google-ads/api/reference/data/codes-formats
    customer.currency_code = "USD"
    customer.time_zone = "America/New_York"
    # The below values are optional. For more information about URL
    # options see: https://support.google.com/google-ads/answer/6305348
    customer.tracking_url_template = "{lpurl}?device={device}"
    customer.final_url_suffix = (
        "keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}"
    )

    response: CreateCustomerClientResponse = (
        customer_service.create_customer_client(
            customer_id=manager_customer_id, customer_client=customer
        )
    )
    print(
        f'Customer created with resource name "{response.resource_name}" '
        f'under manager account with ID "{manager_customer_id}".'
    )
      

Ruby

def create_customer(manager_customer_id)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new

  customer = client.resource.customer do |c|
    c.descriptive_name = "Account created with CustomerService on #{(Time.new.to_f * 1000).to_i}"

    # For a list of valid currency codes and time zones, see this documentation:
    # https://developers.google.com/google-ads/api/reference/data/codes-formats
    c.currency_code = "USD"
    c.time_zone = "America/New_York"

    # The below values are optional. For more information about URL options, see:
    # https://support.google.com/google-ads/answer/6305348
    c.tracking_url_template = "{lpurl}?device={device}"
    c.final_url_suffix = "keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}"
  end

  response = client.service.customer.create_customer_client(
    customer_id: manager_customer_id,
    customer_client: customer
  )

  puts "Created a customer with resource name #{response.resource_name} under" +
      " the manager account with customer ID #{manager_customer_id}."
end
      

Perl

sub create_customer {
  my ($api_client, $manager_customer_id) = @_;

  # Initialize a customer to be created.
  my $customer = Google::Ads::GoogleAds::V26::Resources::Customer->new({
      descriptiveName => "Account created with CustomerService on #" . uniqid(),

      # For a list of valid currency codes and time zones, see this documentation:
      # https://developers.google.com/google-ads/api/reference/data/codes-formats
      currencyCode => "USD",
      timeZone     => "America/New_York",

      # The below values are optional. For more information about URL options, see:
      # https://support.google.com/google-ads/answer/6305348
      trackingUrlTemplate => "{lpurl}?device={device}",
      finalUrlSuffix      =>
        "keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}"
  });

  # Create the customer client.
  my $create_customer_client_response =
    $api_client->CustomerService()->create_customer_client({
      customerId     => $manager_customer_id,
      customerClient => $customer
    });

  printf
    "Created a customer with resource name '%s' under the manager account " .
    "with customer ID %d.\n", $create_customer_client_response->{resourceName},
    $manager_customer_id;

  return 1;
}
      

curl

# Creates a customer client.
#
# Variables:
#   API_VERSION,
#   MANAGER_CUSTOMER_ID,
#   OAUTH2_ACCESS_TOKEN:
#     See https://developers.google.com/google-ads/api/rest/auth#request_headers
#     for details.
#
curl -f --request POST \
"https://googleads.googleapis.com/v${API_VERSION}/customers/${MANAGER_CUSTOMER_ID}:createCustomerClient" \
--header "Content-Type: application/json" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data @- <<EOF
{
  "customerClient": {
    "descriptiveName": "Account created with CustomerService #${RANDOM}",
    "currencyCode": "USD",
    "timeZone": "America/New_York"
  }
}
EOF
      

응답 및 다음 단계

성공하면 CreateCustomerClient는 새로 생성된 계정의 resource_name (customers/{new_customer_id})이 포함된 CreateCustomerClientResponse 를 반환합니다 (허용 목록에 있는 관리자 계정에서 email_address 및 access_role 을 포함한 경우 invitation_link 포함). 그런 다음 이 리소스 이름 또는 고객 ID를 사용하여 계층 구조에서 계정을 확인하거나, 사용자 액세스 권한을 부여하거나, 결제를 구성하거나, 캠페인을 채울 수 있습니다.

관리자 계층 구조에서 생성된 계정 확인

GoogleAdsService.SearchStream 을 사용하여 관리자 계정 (customer_id)에 대해 customer_client 리소스를 쿼리하여 새로 생성된 하위 계정을 검사합니다.

SELECT
  customer_client.id,
  customer_client.resource_name,
  customer_client.client_customer,
  customer_client.descriptive_name,
  customer_client.currency_code,
  customer_client.time_zone,
  customer_client.manager,
  customer_client.level,
  customer_client.status
FROM customer_client
WHERE customer_client.level = 1
  AND customer_client.id = {new_customer_id}

새 계정에 사용자 초대

관리자 계정이 email_address 및 access_role을 CreateCustomerClientRequest에서 직접 설정하기 위한 허용 목록에 없는 경우 새로 생성된 new_customer_id에 액세스 초대장을 CustomerUserAccessInvitationService에서 MutateCustomerUserAccessInvitation을 사용하여 보냅니다. 상위 관리자 계정을 통해 인증할 때 HTTP 요청 헤더에 login-customer-id: {manager_customer_id}를 포함합니다.

POST https://googleads.googleapis.com/v26/customers/{new_customer_id}/customerUserAccessInvitations:mutate
{
  "operation": {
    "create": {
      "emailAddress": "user@example.com",
      "accessRole": "ADMIN"
    }
  }
}

오류 처리

CreateCustomerClient 호출은 다음 오류를 반환할 수 있습니다.

  • CustomerError: CREATION_DENIED_INELIGIBLE_MCC (관리자 계정에서 새 계정을 만들 수 없음) 또는 CREATION_DENIED_FOR_POLICY_VIOLATION (정책 위반으로 인해 고객 생성이 거부됨)과 같은 계정 수준 생성 제한사항을 나타냅니다.
  • ManagerLinkError: 계층 구조 또는 계정 한도 제약 조건(예: TOO_MANY_ACCOUNTS, TOO_MANY_ACCOUNTS_AT_MANAGER, MAX_DEPTH_EXCEEDED)을 나타냅니다.
  • AccessInvitationError: 허용 목록에 있는 계정에서만 사용할 수 있는 access_role와 함께 선택사항인 email_address가 CreateCustomerClientRequest에 제공되어 새 계정에 사용자를 초대하고 초대가 실패하는 경우(예: INVALID_EMAIL_ADDRESS, GOOGLE_CONSUMER_ACCOUNT_NOT_ALLOWED, 또는 EMAIL_DOMAIN_POLICY_VIOLATED) 반환됩니다. 허용 목록에 없는 계정은 계정 생성 후 CustomerUserAccessInvitationService를 사용하여 사용자를 초대해야 합니다.
  • CurrencyCodeError.UNSUPPORTED 또는 TimeZoneError.INVALID_TIME_ZONE: 지정된 currency_code 또는 time_zone이(가) Customer 객체에서 유효하지 않거나 지원되지 않는 경우 반환됩니다.