একটি অ্যাকাউন্ট তৈরি করুন

নতুন ক্লায়েন্ট অ্যাকাউন্ট তৈরি করতে, CustomerService-এ CreateCustomerClient পদ্ধতি ব্যবহার করে আগে থেকেই পূরণ করা Customer অবজেক্ট জমা দিন।

সাধারণ এন্টিটি তৈরি করার (যেমন, mutate কল ব্যবহার করে ক্যাম্পেন তৈরি করা) মতো নয়, আপনাকে তৈরি করা হচ্ছে এমন গ্রাহকের আইডির পরিবর্তে অনুরোধে ম্যানেজার অ্যাকাউন্টের গ্রাহক আইডি উল্লেখ করতে হবে।

অনুরোধ ও গ্রাহক ফিল্ড

CustomerService.CreateCustomerClient কল করার সময়, CreateCustomerClientRequest এবং এর নেস্টেড Customer অবজেক্ট কনফিগার করুন, যেমনটি নিম্নলিখিত টেবিলে দেখানো হয়েছে:

ফিল্ড বা হেডার এই ব্যাজ অর্জন করার জন্য প্রয়োজনীয় যোগ্যতা পরিবর্তনযোগ্যতা ও বিবরণ
customer_id প্রয়োজনীয় নতুন ক্লায়েন্ট অ্যাকাউন্ট যে ডাইরেক্ট পেরেন্ট ম্যানেজার অ্যাকাউন্টের অধীনে তৈরি করা হয়েছে তার ১০-সংখ্যার গ্রাহক আইডি (হাইফেন ছাড়া)।
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;
}
      

কার্ল

# 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}) থাকে (এছাড়াও, invitation_link থাকে যদি email_address এবং access_role ম্যানেজার অ্যাকাউন্ট দ্বারা অনুমোদিত তালিকায় অন্তর্ভুক্ত করা হয়)। তারপর আপনি এই রিসোর্স নাম বা কাস্টমার আইডি ব্যবহার করে আপনার হায়ারার্কিতে অ্যাকাউন্ট যাচাই করতে, ব্যবহারকারীকে অ্যাক্সেস দিতে, বিলিং কনফিগার করতে বা ক্যাম্পেন পপুলেট করতে পারবেন।

ম্যানেজার হায়ারার্কিতে তৈরি করা অ্যাকাউন্ট যাচাই করুন

নতুন তৈরি করা সাব-অ্যাকাউন্ট চেক করতে 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-এ অ্যাক্সেস ইনভাইট পাঠান, এটি MutateCustomerUserAccessInvitation-এ CustomerUserAccessInvitationService ব্যবহার করে করুন। পেরেন্ট ম্যানেজার অ্যাকাউন্টের মাধ্যমে যাচাই করার সময়, 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: নতুন অ্যাকাউন্টে কোনও ব্যবহারকারীকে আমন্ত্রণ জানাতে 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 ভুল অথবা কাজ করে না, সেই ক্ষেত্রে এই কোড রিটার্ন করা হয়।