Yeni bir müşteri hesabı oluşturmak için CustomerService üzerinde CreateCustomerClient yöntemini kullanarak önceden doldurulmuş bir Customer nesnesi gönderin.
Standart öğe oluşturma işleminden (ör. mutate çağrılarını kullanarak kampanya oluşturma) farklı olarak, istekte oluşturulan müşterinin kimliği yerine yönetici hesabının müşteri kimliğini belirtmeniz gerekir.
İstek ve müşteri alanları
CustomerService.CreateCustomerClient yöntemini çağırırken CreateCustomerClientRequest ve iç içe yerleştirilmiş Customer nesnesini aşağıdaki tabloda gösterildiği gibi yapılandırın:
| Alan veya başlık | Gereksinim | Değişebilirlik ve açıklama |
|---|---|---|
customer_id |
Zorunlu | Yeni müşteri hesabının oluşturulduğu doğrudan üst yönetici hesabının 10 haneli müşteri kimliği (tireler olmadan). |
login-customer-id (başlık) |
Şart Kipi | Kimliği doğrulanmış kullanıcı, üst yönetici hesabına (customer_id) hiyerarşide daha üstte bulunan bir üst yönetici hesabı üzerinden erişiyorsa istek başlıklarında zorunludur. |
customer_client.descriptive_name |
Zorunlu | Değiştirilebilir: Yeni hesabın görünen adı (ör. "Acct Created with CustomerService"). Daha sonra CustomerService.MutateCustomer ile güncellenebilir. |
customer_client.currency_code |
Zorunlu | Oluşturulduktan sonra değiştirilemez: 3 karakterli ISO 4217 faturalandırma para birimi kodu (örneğin, USD veya EUR). Desteklenen para birimi kodlarına bakın. |
customer_client.time_zone |
Zorunlu | Oluşturulduktan sonra değiştirilemez: Hesap saat dilimi kimliği (örneğin, America/New_York). Desteklenen saat dilimlerine bakın. |
email_address ve access_role |
İsteğe bağlı (yalnızca izin verilenler listesi) | Oluşturma sırasında bir kullanıcıyı (ADMIN, STANDARD, READ_ONLY veya EMAIL_ONLY) oluşturulan hesaba davet eder. İzin verilenler listesinde olmayan hesaplar, oluşturulduktan sonra kullanıcıları CustomerUserAccessInvitationService kullanarak davet etmelidir. |
validate_only |
İsteğe bağlı | true olduğunda, hesabı oluşturmadan istek parametrelerini ve yönetici uygunluğunu doğrular. |
Kod örneği
Aşağıdaki örnekte, mevcut bir yönetici hesabı altında müşteri hesabının nasıl oluşturulacağı gösterilmektedir:
Java
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
Yanıt ve sonraki adımlar
İşlem başarılı olursa CreateCustomerClient, yeni oluşturulan hesabın resource_name (customers/{new_customer_id}) değerini içeren bir CreateCustomerClientResponse döndürür (email_address ve access_role izin verilenler listesindeki bir yönetici hesabı tarafından dahil edildiyse invitation_link de döndürülür). Ardından, hiyerarşinizdeki hesabı doğrulamak, kullanıcı erişimi vermek, faturalandırmayı yapılandırmak veya kampanyaları doldurmak için bu kaynak adını ya da müşteri kimliğini kullanabilirsiniz.
Oluşturulan hesabı yönetici hiyerarşisinde doğrulama
Yeni oluşturulan alt hesabı incelemek için GoogleAdsService.SearchStream kullanarak yönetici hesabında (customer_id) customer_client kaynağını sorgulayın:
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}
Kullanıcıları yeni hesaba davet etme
Yönetici hesabınız, email_address ve access_role değerlerini doğrudan CreateCustomerClientRequest üzerinde ayarlamak için izin verilenler listesinde değilse CustomerUserAccessInvitationService üzerinde MutateCustomerUserAccessInvitation kullanarak yeni oluşturulan new_customer_id hesabına erişim daveti gönderin. Üst yönetici hesabı üzerinden kimlik doğrulaması yaparken HTTP istek başlıklarına login-customer-id: {manager_customer_id} parametresini ekleyin:
POST https://googleads.googleapis.com/v26/customers/{new_customer_id}/customerUserAccessInvitations:mutate
{
"operation": {
"create": {
"emailAddress": "user@example.com",
"accessRole": "ADMIN"
}
}
}
Hata işleme
CreateCustomerClient çağrıları aşağıdaki hataları döndürebilir:
CustomerError: Hesap düzeyinde oluşturma kısıtlamalarını gösterir. Örneğin,CREATION_DENIED_INELIGIBLE_MCC(yönetici hesabı yeni hesap oluşturmaya uygun değil) veyaCREATION_DENIED_FOR_POLICY_VIOLATION(politika ihlali nedeniyle müşteri oluşturma reddedildi).ManagerLinkError:TOO_MANY_ACCOUNTS,TOO_MANY_ACCOUNTS_AT_MANAGERveyaMAX_DEPTH_EXCEEDEDgibi hiyerarşi ya da hesap sınırı kısıtlamalarını belirtir.AccessInvitationError: Bir kullanıcıyı yeni hesaba davet etmek içinCreateCustomerClientRequestüzerinde isteğe bağlı biremail_address(yalnızca izin verilenler listesindeki hesaplar tarafından kullanılabilenaccess_roleile birlikte) sağlanırsa ve davet başarısız olursa (ör.INVALID_EMAIL_ADDRESS,GOOGLE_CONSUMER_ACCOUNT_NOT_ALLOWEDveyaEMAIL_DOMAIN_POLICY_VIOLATED) döndürülür. İzin verilenler listesinde olmayan hesaplar, hesap oluşturulduktan sonraCustomerUserAccessInvitationServicekullanarak kullanıcıları davet etmelidir.CurrencyCodeError.UNSUPPORTEDveyaTimeZoneError.INVALID_TIME_ZONE:Customernesnesinde belirtilencurrency_codeveyatime_zonegeçersiz ya da desteklenmediğinde döndürülür.