नया क्लाइंट खाता बनाने के लिए, CustomerService पर CreateCustomerClient तरीके का इस्तेमाल करके, अपने-आप जानकारी भरने वाला Customer ऑब्जेक्ट सबमिट करें.
स्टैंडर्ड तरीके से इकाई बनाने (जैसे कि mutate कॉल का इस्तेमाल करके कैंपेन बनाना) के उलट, आपको अनुरोध में बनाए जा रहे ग्राहक के आईडी के बजाय, मैनेजर खाते का ग्राहक आईडी बताना होगा.
अनुरोध और ग्राहक से जुड़े फ़ील्ड
CustomerService.CreateCustomerClient को कॉल करते समय, CreateCustomerClientRequest और उसके नेस्ट किए गए Customer ऑब्जेक्ट को कॉन्फ़िगर करें. इसके लिए, यहां दी गई टेबल देखें:
| फ़ील्ड या हेडर | आवश्यकता | म्यूटेबिलिटी और ब्यौरा |
|---|---|---|
customer_id |
ज़रूरी है | उस डायरेक्ट पैरंट मैनेजर खाते का 10 अंकों वाला ग्राहक आईडी (बिना हाइफ़न के) जिसके तहत नया क्लाइंट खाता बनाया गया है. |
login-customer-id (हेडर) |
कंडीशनल | अगर पुष्टि किया गया उपयोगकर्ता, हैरारकी में ऊपर मौजूद पैरंट मैनेजर खाते (customer_id) को ऐक्सेस करता है, तो अनुरोध के हेडर में यह ज़रूरी है. |
customer_client.descriptive_name |
ज़रूरी है | बदला जा सकता है: नए खाते का डिसप्ले नेम (उदाहरण के लिए, "Acct Created with CustomerService"). इसे बाद में CustomerService.MutateCustomer की मदद से अपडेट किया जा सकता है. |
customer_client.currency_code |
ज़रूरी है | बनाने के बाद नहीं बदला जा सकता: तीन वर्णों वाला ISO 4217 बिलिंग करंसी कोड (उदाहरण के लिए, USD या EUR). इस्तेमाल किए जा सकने वाले करंसी कोड देखें. |
customer_client.time_zone |
ज़रूरी है | खाता बनाने के बाद, इसमें बदलाव नहीं किया जा सकता: खाते का टाइम ज़ोन आईडी (उदाहरण के लिए, America/New_York). इस्तेमाल किए जा सकने वाले टाइम ज़ोन देखें. |
email_address और access_role |
ज़रूरी नहीं (सिर्फ़ अनुमति वाली सूची के लिए) | खाता बनाने के दौरान, किसी उपयोगकर्ता (ADMIN, STANDARD, READ_ONLY या EMAIL_ONLY) को बनाए गए खाते में शामिल होने का न्योता भेजता है. अनुमति वाली सूची में शामिल नहीं किए गए खातों को, खाता बनाने के बाद CustomerUserAccessInvitationService का इस्तेमाल करके उपयोगकर्ताओं को न्योता भेजना होगा. |
validate_only |
वैकल्पिक | true होने पर, खाता बनाए बिना ही अनुरोध के पैरामीटर और मैनेजर की ज़रूरी शर्तों की पुष्टि करता है. |
कोड का उदाहरण
इस उदाहरण में, किसी मौजूदा मैनेजर खाते में ग्राहक खाता बनाने का तरीका बताया गया है:
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
जवाब और अगले चरण
काम पूरा होने पर, CreateCustomerClient एक CreateCustomerClientResponse दिखाता है. इसमें नए बनाए गए खाते का resource_name (customers/{new_customer_id}) शामिल होता है. साथ ही, अगर अनुमति वाली सूची में शामिल किसी मैनेजर खाते ने email_address और access_role को शामिल किया है, तो invitation_link भी शामिल होता है. इसके बाद, इस संसाधन के नाम या ग्राहक आईडी का इस्तेमाल करके, अपनी हैरारकी में मौजूद खाते की पुष्टि की जा सकती है. साथ ही, उपयोगकर्ता को ऐक्सेस दिया जा सकता है, बिलिंग कॉन्फ़िगर की जा सकती है या कैंपेन बनाए जा सकते हैं.
मैनेजर खाते की हैरारकी में, बनाए गए खाते की पुष्टि करना
नए उप-खाते की जांच करने के लिए, 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}
उपयोगकर्ताओं को नए खाते का न्योता देना
अगर आपका मैनेजर खाता, CreateCustomerClientRequest पर सीधे तौर पर email_address और access_role सेट करने की अनुमति वाली सूची में शामिल नहीं है, तो CustomerUserAccessInvitationService पर MutateCustomerUserAccessInvitation का इस्तेमाल करके, नए बनाए गए new_customer_id को ऐक्सेस करने का न्योता भेजें. पैरंट मैनेजर खाते से पुष्टि करते समय, एचटीटीपी अनुरोध के हेडर में 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: यह गड़बड़ी तब दिखती है, जब किसी उपयोगकर्ता को नए खाते में शामिल होने का न्योता भेजने के लिए,CreateCustomerClientRequestपर वैकल्पिकemail_address(access_roleके साथ, सिर्फ़ अनुमति वाली सूची में शामिल खातों के लिए उपलब्ध) दिया जाता है और न्योता नहीं भेजा जा पाता. उदाहरण के लिए,INVALID_EMAIL_ADDRESS,GOOGLE_CONSUMER_ACCOUNT_NOT_ALLOWEDयाEMAIL_DOMAIN_POLICY_VIOLATED. अनुमति वाली सूची में शामिल नहीं किए गए खातों को, खाता बनाने के बादCustomerUserAccessInvitationServiceका इस्तेमाल करके उपयोगकर्ताओं को न्योता भेजना चाहिए.CurrencyCodeError.UNSUPPORTEDयाTimeZoneError.INVALID_TIME_ZONE: यह गड़बड़ी तब दिखती है, जबCustomerऑब्जेक्ट पर मौजूदcurrency_codeयाtime_zoneअमान्य हो या काम न करता हो.