สร้างบัญชี

คุณใช้ Merchant API เพื่อสร้างบัญชี Merchant Center ซึ่งสามารถลิงก์กับบัญชีขั้นสูงได้โดยใช้ accountAggregation, accountManagement หรือ comparisonShopping เมธอด accounts.createAndConfigure ช่วยให้คุณสร้างบัญชีและกำหนดค่าบัญชีด้วยผู้ใช้ รวมถึงลิงก์บัญชีกับบัญชีอื่นๆ ผ่านบริการได้ (ไม่บังคับ)

คู่มือนี้จะอธิบายวิธีใช้ Merchant API เพื่อสร้างบัญชีโดยใช้ accountAggregation, accountManagement หรือ comparisonShopping ดังนี้

  • accountAggregation: ใช้โดยมาร์เก็ตเพลส ผู้ค้าปลีกหลายแบรนด์ ผู้ค้าปลีกระหว่างประเทศ และพาร์ทเนอร์ที่สร้างบัญชีย่อยภายใต้บัญชีขั้นสูงแบบหลายลูกค้า
  • accountManagement: ใช้โดยเอเจนซีที่สร้างบัญชีแบบสแตนด์อโลนซึ่งผู้ขายเป็นเจ้าของ
  • comparisonShopping: ใช้โดยบริการช็อปปิ้งแบบเปรียบเทียบสินค้า (CSS) ที่สร้างบัญชีใน EEA และประเทศที่มีสิทธิ์ใช้ CSS

เมื่อใช้ accounts.createAndConfigure คุณต้องลิงก์บัญชีใหม่กับผู้ให้บริการโดยระบุ accountAggregation, accountManagement หรือ comparisonShopping อย่างน้อย 1 รายการในช่อง service คุณสามารถระบุ accountAggregation และ comparisonShopping ในคำขอเดียวกันได้ แต่ไม่สามารถรวม accountManagement กับ accountAggregation หรือ comparisonShopping ได้ หากระบุ accountManagement ให้เพิ่มผู้ใช้อย่างน้อย 1 รายในบัญชีใหม่โดยใช้ช่อง user หรือ users

ข้อกำหนดเบื้องต้น

ก่อนที่จะสร้างบัญชีโดยใช้ Merchant API โปรดตรวจสอบว่าคุณมีคุณสมบัติตรงตามข้อกำหนดต่อไปนี้ ทั้งนี้ขึ้นอยู่กับบริการที่คุณใช้

  • สิทธิ์เข้าถึงระดับผู้ดูแลระบบ: คุณต้องมีสิทธิ์เข้าถึงระดับผู้ดูแลระบบในบัญชีผู้ให้บริการเมื่อลิงก์บัญชีใหม่โดยใช้ accountManagement, comparisonShopping หรือ accountAggregation
  • บัญชีขั้นสูง: หากคุณใช้ accountAggregation บัญชีผู้ให้บริการของคุณต้องเป็นบัญชีขั้นสูงที่กำหนดค่าสำหรับการรวมบัญชี หากคุณเป็นผู้ให้บริการและต้องการตั้งค่าบัญชีขั้นสูง โปรดติดต่อทีมสนับสนุนเพื่อขอความช่วยเหลือเกี่ยวกับการกำหนดค่า

สร้างบัญชี (โดยใช้การจัดการบัญชีหรือบริการช็อปปิ้งแบบเปรียบเทียบสินค้า)

หากต้องการสร้างบัญชีใหม่ โปรดโทรไปที่ accounts.createAndConfigure เราขอแนะนำให้พาร์ทเนอร์ที่ช่วยผู้ขายจัดการบัญชีใช้วิธีนี้ เนื่องจากจะช่วยให้ผู้ขายควบคุมและเป็นเจ้าของบัญชีได้อย่างเต็มที่ ขณะเดียวกันก็ให้สิทธิ์ที่เฉพาะเจาะจงแก่พาร์ทเนอร์ได้

ในเนื้อหาคำขอ ให้ทำดังนี้

  1. ระบุรายละเอียดของบัญชีที่ต้องการสร้างในช่อง account
  2. ในช่อง accountName อย่าใช้เครื่องหมายวรรคตอน อักษรตัวพิมพ์ใหญ่ ขีดล่าง อักษรตัวพิมพ์ใหญ่ทั้งหมด อีโมจิ หรือสัญลักษณ์ที่ไม่ใช่ตัวอักษรและตัวเลขคละกัน เช่น / หรือ _ ที่ซ้ำและไม่จำเป็น หลีกเลี่ยงคำต่อท้ายชื่อธุรกิจ (เช่น "Inc." หรือ "GmbH") ข้อความโปรโมต ข้อมูลส่วนบุคคล หรือภาษาที่ไม่เหมาะสม ใช้ชื่อที่สั้น ชัดเจน และเป็นมืออาชีพ ดูข้อมูลเพิ่มเติมได้ที่การเพิ่มชื่อธุรกิจ
  3. หากคุณใช้ accountManagement ให้ระบุผู้ใช้อย่างน้อย 1 รายในช่อง user ซึ่งจะมีสิทธิ์เข้าถึงบัญชี
  4. ในช่อง service ให้ระบุบริการที่ต้องการมอบให้บัญชีนี้ เช่น accountManagement และตั้งค่า provider เป็นชื่อทรัพยากรของบัญชี (เช่น providers/{YOUR_ACCOUNT_ID}) ดูรายการบริการที่ใช้ได้ เช่น productsManagement หรือ campaignsManagement ได้ที่หัวข้อจัดการความสัมพันธ์ของบัญชี

ต่อไปนี้คือตัวอย่างคำขอสร้างบัญชีชื่อ "merchantStore" และลิงก์กับบัญชี {YOUR_ACCOUNT_ID} เพื่อจัดการบัญชีและผลิตภัณฑ์

POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
  "account": {
    "accountName": "merchantStore",
    "adultContent": false,
    "timeZone": {
      "id": "America/New_York"
    },
    "languageCode": "en-US"
  },
  "user": [
    {
      "userId": "test@example.com",
      "user": {
        "accessRights": ["ADMIN"]
      }
    }
  ],
  "service": [
    {
      "accountManagement": {},
      "provider": "providers/{YOUR_ACCOUNT_ID}"
    },
    {
      "productsManagement": {},
      "provider": "providers/{YOUR_ACCOUNT_ID}"
    }
  ]
}

การเรียกใช้ที่สำเร็จจะสร้างบัญชีใหม่และลิงก์กับบัญชีของคุณสำหรับบริการที่ระบุ หากคุณระบุบริการ accountManagement, accountAggregation หรือ comparisonShopping ในระหว่างการสร้าง ระบบจะอนุมัติบริการเหล่านั้นโดยอัตโนมัติและสถานะลิงก์จะเป็น ESTABLISHED ลิงก์บริการอื่นๆ อาจอยู่ในสถานะ PENDING จนกว่าบัญชีที่สร้างจะยอมรับ เนื้อหาการตอบกลับจะมีทรัพยากร Account ที่สร้างขึ้นใหม่

ตัวอย่างต่อไปนี้แสดงวิธีใช้ accounts.createAndConfigure เพื่อสร้างและกำหนดค่าบัญชี

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccessRight;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountManagement;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddUser;
import com.google.shopping.merchant.accounts.v1.ProductsManagement;
import com.google.shopping.merchant.accounts.v1.User;
import com.google.type.TimeZone;
import java.util.List;
import shopping.merchant.samples.utils.Authenticator;

/**
 * This class demonstrates how to create a new Merchant Center account and configure it with various
 * services.
 */
public class CreateAndConfigureAccountSample {

  public static void createAndConfigureAccount(
      long providerId, String newAccountName, String userEmail) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    AccountsServiceSettings accountsServiceSettings =
        AccountsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (AccountsServiceClient accountsServiceClient =
        AccountsServiceClient.create(accountsServiceSettings)) {

      // The account to be created.
      Account account =
          Account.newBuilder()
              .setAccountName(newAccountName)
              .setTimeZone(TimeZone.newBuilder().setId("Europe/Zurich").build())
              .setLanguageCode("en-US")
              .build();

      // The services to be added to the new account.
      // This sample shows how to configure a new account with account management and
      // product management.
      // For more information about the different services, see:
      // https://developers.google.com/merchant/api/guides/accounts/services
      AddAccountService accountManagementService =
          AddAccountService.newBuilder()
              .setProvider("accounts/" + providerId)
              .setExternalAccountId("external_account_id")
              .setAccountManagement(AccountManagement.newBuilder().build())
              .build();
      // This part is optional. You can also omit this and link the account later.
      AddAccountService productsManagementService =
          AddAccountService.newBuilder()
              .setProvider("accounts/" + providerId)
              .setExternalAccountId("external_account_id")
              .setProductsManagement(ProductsManagement.newBuilder().build())
              .build();

      // For sub-account creation, use the AccountAggregation service. For an example on how to do
      // this, see the `CreateSubAccount` sample.

      // The user to be added to the new account.
      // This part is optional.
      AddUser user =
          AddUser.newBuilder()
              .setUserId(userEmail)
              .setUser(User.newBuilder().addAccessRights(AccessRight.STANDARD).build())
              .build();

      CreateAndConfigureAccountRequest request =
          CreateAndConfigureAccountRequest.newBuilder()
              .setAccount(account)
              .addAllService(List.of(accountManagementService, productsManagementService))
              .addUser(user)
              .build();

      System.out.println("Sending Create and Configure Account request:");
      Account response = accountsServiceClient.createAndConfigureAccount(request);

      System.out.println("Created Account below");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    // This is the provider ID of the e-commerce platform.
    long providerId = 123L;
    // This is the name of the new account to be created.
    String newAccountName = "MyNewShop";
    // This is the email of a user to be added to the new account.
    String userEmail = "test-user@gmail.com";
    createAndConfigureAccount(providerId, newAccountName, userEmail);
  }
}

หลังจากสร้างบัญชีดังกล่าวแล้ว คุณต้องเริ่มต้นใช้งานโดยทำตามขั้นตอนต่างๆ เช่น ยอมรับข้อกำหนดในการให้บริการ ตั้งค่าข้อมูลทางธุรกิจ และยืนยันเว็บไซต์

ระงับการยืนยันอีเมลระหว่างการสร้างบัญชี

เมื่อสร้างบัญชีด้วย accounts.createAndConfigure คุณสามารถเลือกที่จะระงับอีเมลยืนยันสำหรับผู้ใช้ใหม่ที่เพิ่มโดยใช้ช่อง user ได้โดยตั้งค่า verificationMailSettings.verificationMailMode เป็น SUPPRESS_VERIFICATION_MAIL ในคำขอสำหรับผู้ใช้รายนั้น ซึ่งจะเป็นประโยชน์หากคุณต้องการยืนยันผู้ใช้ในนามของผู้ขายทันทีหลังจากสร้างโดยใช้วิธี users.verifySelf โดยค่าเริ่มต้น verificationMailMode จะเป็น SEND_VERIFICATION_MAIL และระบบจะส่งอีเมลยืนยันไปยังผู้ใช้ใหม่ที่เพิ่มเข้ามาในระหว่างการสร้างบัญชี

POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
  "account": {
    "accountName": "merchantStore",
    "adultContent": false,
    "timeZone": {
      "id": "America/New_York"
    },
    "languageCode": "en-US"
  },
  "user": [
    {
      "userId": "test@example.com",
      "user": {
        "accessRights": ["ADMIN"]
      },
      "verificationMailSettings": {
        "verificationMailMode": "SUPPRESS_VERIFICATION_MAIL"
      }
    }
  ],
  "service": [
    {
      "accountManagement": {},
      "provider": "providers/{YOUR_ACCOUNT_ID}"
    }
  ]
}

หากตั้งค่า verificationMailMode เป็น SUPPRESS_VERIFICATION_MAIL คุณต้องเรียกใช้ users.verifySelf สำหรับผู้ใช้แต่ละรายที่เพิ่มระหว่างการสร้างเพื่อทำการยืนยันให้เสร็จสมบูรณ์ การเรียกนี้ต้องได้รับการตรวจสอบสิทธิ์ในฐานะผู้ใช้ที่ได้รับการยืนยัน (ผู้ใช้ที่ระบุใน userId) เช่น การใช้โทเค็น OAuth จากผู้ใช้

ระบุชื่อแทนในระหว่างการสร้างบัญชี

คุณสามารถระบุชื่อแทนสำหรับบัญชีในบริบทของผู้ให้บริการใน CreateAndConfigureAccountRequest โดยใช้ช่อง setAlias คุณสามารถใช้ชื่อแทนเพื่อระบุบัญชีในระบบได้ หากคุณเป็นผู้ให้บริการ คุณสามารถใช้นามแฝงเพื่อเรียกข้อมูลบัญชีโดยใช้ GET /accounts/v1/accounts/{provider}~{alias} ชื่อแทนต้องไม่ซ้ำกันสำหรับผู้ให้บริการที่ระบุ และคุณต้องระบุบริการที่มีผู้ให้บริการรายเดียวกันในช่อง service ของคำขอ ดูข้อมูลเพิ่มเติมเกี่ยวกับข้อกำหนดของชื่อแทนได้ที่หัวข้อจัดการความสัมพันธ์ของบัญชี

POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
  "account": {
    "accountName": "merchantStore",
    "adultContent": false,
    "timeZone": {
      "id": "America/New_York"
    },
    "languageCode": "en-US"
  },
  "service": [
    {
      "accountManagement": {},
      "provider": "providers/{YOUR_ACCOUNT_ID}"
    }
  ],
  "setAlias": [
    {
      "provider": "providers/{YOUR_ACCOUNT_ID}",
      "accountIdAlias": "my-merchant-alias"
    }
  ]
}

หากคุณเป็นพาร์ทเนอร์ที่สร้างบัญชีในนามของผู้ขาย เราขอแนะนำให้ทำตามขั้นตอนต่อไปนี้

  1. สร้างบัญชี: เรียกใช้ accounts.createAndConfigure ด้วยข้อมูลเข้าสู่ระบบของพาร์ทเนอร์เพื่อสร้างบัญชีใหม่
    • ตั้งค่า service ให้รวม accountManagement ที่ลิงก์กับรหัสผู้ให้บริการ
    • เพิ่มผู้ขายเป็นผู้ใช้โดยใช้ช่อง user และตั้งค่า verificationMailSettings.verificationMailMode เป็น SUPPRESS_VERIFICATION_MAIL
  2. ยืนยันผู้ใช้: ด้วยข้อมูลเข้าสู่ระบบจากผู้ขาย (เช่น การใช้โทเค็น OAuth) ให้เรียกใช้ users.verifySelf เพื่อเปลี่ยนสถานะผู้ใช้จาก PENDING เป็น VERIFIED
  3. ตั้งค่าประเทศของธุรกิจ: ตั้งค่าประเทศของธุรกิจด้วยข้อมูลเข้าสู่ระบบของผู้ขายโดยอัปเดต address.regionCode โดยใช้ accounts.updateBusinessInfo คุณต้องดำเนินการนี้ก่อนยอมรับข้อกำหนดในการให้บริการ
  4. ยอมรับข้อกำหนดในการให้บริการ : ยอมรับข้อกำหนดในการให้บริการ ด้วยข้อมูลเข้าสู่ระบบของผู้ขาย

ขั้นตอนการเริ่มต้นใช้งานนี้ช่วยให้ผู้ขายเริ่มต้นใช้งานภายในแพลตฟอร์มของคุณได้อย่างราบรื่นโดยไม่ต้องรับอีเมลคำเชิญจาก Google

สร้างบัญชีลูกค้า (โดยใช้การรวมบัญชี)

บัญชีลูกค้าคือบัญชี Merchant Center ที่แยกต่างหากซึ่งลิงก์กับบัญชีขั้นสูงของคุณโดยใช้บริการ accountAggregation ซึ่งช่วยให้จัดการแบบรวมศูนย์ได้ในขณะที่ยังคงรักษาการตั้งค่า เว็บไซต์ และฟีดข้อมูลแยกต่างหากไว้ คุณใช้ API ย่อยของบัญชีผู้ขายเพื่อสร้างบัญชีลูกค้าใหม่ได้

หากต้องการสร้างบัญชีลูกค้า คุณต้องมีการสร้างบัญชีขั้นสูงก่อน คุณต้องเป็นผู้ดูแลบัญชีจึงจะแปลงบัญชี Merchant Center เป็นบัญชีขั้นสูงได้ และบัญชีต้องไม่มีปัญหาที่รอดำเนินการ

หากต้องการสร้างบัญชีลูกค้าใหม่ ให้เรียกใช้ accounts.createAndConfigure ในเนื้อหาคำขอ ให้ทำดังนี้

  1. ระบุรายละเอียดของบัญชีที่ต้องการสร้างในช่อง account
  2. ในช่อง accountName อย่าใช้เครื่องหมายวรรคตอน อักษรตัวพิมพ์ใหญ่ ขีดล่าง หรือสัญลักษณ์ที่ไม่ใช่ตัวอักษรและตัวเลขคละกัน (เช่น "/" หรือ "_") ที่ซ้ำและไม่จำเป็น หลีกเลี่ยงคำต่อท้ายชื่อธุรกิจ (เช่น "Inc." หรือ "GmbH") ข้อความโปรโมต ข้อมูลส่วนบุคคล หรือภาษาที่ไม่เหมาะสม ใช้ชื่อที่สั้น ชัดเจน และเป็นมืออาชีพ ดูข้อมูลเพิ่มเติมได้ที่การเพิ่มชื่อธุรกิจ
  3. หรือจะระบุผู้ใช้ที่ได้รับอนุญาตรายใหม่ในช่อง user ก็ได้ สิทธิ์เข้าถึงของผู้ใช้สำหรับบัญชีจะรับช่วงมาจากบัญชีขั้นสูงหลักด้วย
  4. ในช่อง service ให้ระบุ accountAggregation และตั้งค่า provider เป็นชื่อทรัพยากรของบัญชีขั้นสูง (เช่น providers/{ADVANCED_ACCOUNT_ID}) ซึ่งจะกำหนดให้บัญชีขั้นสูงเป็นผู้รวบรวมบัญชีใหม่

ต่อไปนี้เป็นตัวอย่างคำขอสร้างบัญชีลูกค้าชื่อ "merchantStore" ที่ลิงก์กับบัญชีขั้นสูง {ADVANCED_ACCOUNT_ID}

POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
  "account": {
    "accountName": "merchantStore",
    "adultContent": false,
    "timeZone": {
      "id": "America/New_York"
    },
    "languageCode": "en-US"
  },
  "service": [
    {
      "accountAggregation": {},
      "provider": "providers/{ADVANCED_ACCOUNT_ID}"
    }
  ]
}

การเรียกใช้ที่สำเร็จจะสร้างบัญชีลูกค้าใหม่และลิงก์กับบัญชีขั้นสูงที่ระบุ เนื้อหาการตอบกลับจะมีทรัพยากร Account ที่สร้างขึ้นใหม่

ตัวอย่างต่อไปนี้แสดงวิธีใช้ accounts.createAndConfigure เพื่อสร้างบัญชีลูกค้าใหม่

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountAggregation;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.type.TimeZone;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to create a sub-account under an advanced account. */
public class CreateSubAccountSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static Account createSubAccount(Config config) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    AccountsServiceSettings accountsServiceSettings =
        AccountsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates parent/provider to identify the advanced account into which to insert the subaccount.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (AccountsServiceClient accountsServiceClient =
        AccountsServiceClient.create(accountsServiceSettings)) {

      CreateAndConfigureAccountRequest request =
          CreateAndConfigureAccountRequest.newBuilder()
              .setAccount(
                  Account.newBuilder()
                      .setAccountName("Demo Business")
                      .setAdultContent(false)
                      .setTimeZone(TimeZone.newBuilder().setId("America/New_York").build())
                      .setLanguageCode("en-US")
                      .build())
              .addService(
                  AddAccountService.newBuilder()
                      .setProvider(parent)
                      .setAccountAggregation(AccountAggregation.getDefaultInstance())
                      .build())
              .build();

      System.out.println("Sending Create SubAccount request");
      Account response = accountsServiceClient.createAndConfigureAccount(request);
      System.out.println("Inserted Account Name below");
      // Format: `accounts/{account}`
      System.out.println(response.getName());
      return response;
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    createSubAccount(config);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Account;
use Google\Shopping\Merchant\Accounts\V1\AccountAggregation;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\CreateAndConfigureAccountRequest;
use Google\Shopping\Merchant\Accounts\V1\CreateAndConfigureAccountRequest\AddAccountService;
use Google\Type\TimeZone;

/**
 * This class demonstrates how to create a sub-account under an MCA account.
 */
class CreateSubAccount
{

    private static function getParent(string $accountId): string
    {
        return sprintf("accounts/%s", $accountId);
    }


    public static function createSubAccount(array $config): void
    {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options config containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a client.
        $accountsServiceClient = new AccountsServiceClient($options);

        // Creates parent/provider to identify the MCA account into which to insert the subaccount.
        $parent = self::getParent($config['accountId']);

        // Calls the API and catches and prints any network failures/errors.
        try {
            $request = new CreateAndConfigureAccountRequest([
                'account' => (new Account([
                    'account_name' => 'Demo Business',
                    'adult_content' => false,
                    'time_zone' => (new TimeZone(['id' => 'America/New_York'])),
                    'language_code' => 'en-US',
                ])),
                'service' => [
                    (new AddAccountService([
                        'provider' => $parent,
                        'account_aggregation' => new AccountAggregation,
                    ])),
                ],
            ]);

            print "Sending Create SubAccount request\n";
            $response = $accountsServiceClient->createAndConfigureAccount($request);
            print "Inserted Account Name below\n";
            // Format: `accounts/{account}
            print $response->getName() . PHP_EOL;
        } catch (ApiException $e) {
            print $e->getMessage();
        }
    }
    public function callSample(): void
    {
        $config = Config::generateConfig();
        self::createSubAccount($config);
    }
}

$sample = new CreateSubAccount();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import Account
from google.shopping.merchant_accounts_v1 import AccountAggregation
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import CreateAndConfigureAccountRequest


def get_parent(account_id):
  return f"accounts/{account_id}"


def create_sub_account(account_id: str) -> Account:
  """Creates a sub-account under an advanced account."""

  # Get OAuth credentials.
  credentials = generate_user_credentials.main()

  # Create a client.
  client = AccountsServiceClient(credentials=credentials)

  # Get the parent advanced account ID.
  parent = get_parent(account_id)

  # Create the request.
  request = CreateAndConfigureAccountRequest(
      account=Account(
          account_name="Demo Business",
          adult_content=False,
          time_zone={"id": "America/New_York"},
          language_code="en-US",
      ),
      service=[
          CreateAndConfigureAccountRequest.AddAccountService(
              provider=parent,
              account_aggregation=AccountAggregation(),
          )
      ],
  )

  # Make the request and print the response.
  try:
    print("Sending Create SubAccount request")
    response = client.create_and_configure_account(request=request)
    print("Inserted Account Name below")
    print(response.name)
    return response
  except RuntimeError as e:
    print(e)
    raise


if __name__ == "__main__":
  _account_id = configuration.Configuration().read_merchant_info()
  create_sub_account(_account_id)

cURL

curl -X POST \
"https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
  "account": {
    "accountName": "Demo Business",
    "adultContent": false,
    "timeZone": {
      "id": "America/New_York"
    },
    "languageCode": "en-US"
  },
  "service": [
    {
      "accountAggregation": {},
      "provider": "providers/{ADVANCED_ACCOUNT_ID}"
    }
  ]
}'

เรียกข้อมูลบัญชีลูกค้า

หากต้องการแสดงรายการบัญชีลูกค้าทั้งหมดของบัญชีขั้นสูงที่ระบุ ให้ใช้เมธอด accounts.listSubaccounts ระบุรหัสของบัญชีขั้นสูงในช่อง provider ของ URL คำขอ

ตัวอย่างคำขอมีดังนี้

GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts

ต่อไปนี้เป็นตัวอย่างการตอบกลับจากการเรียกใช้ที่สำเร็จ

{
"accounts": [
    {
      "name": "accounts/<var class=\"readonly\">{SUB_ACCOUNT_ID_1}</var>",
      "accountId": "<var class=\"readonly\">{SUB_ACCOUNT_ID_1}</var>",
      "accountName": "<var class=\"readonly\">{SUB_ACCOUNT_NAME_1}</var>",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    },
    {
      "name": "accounts/<var class=\"readonly\">{SUB_ACCOUNT_ID_2}</var>",
      "accountId": "<var class=\"readonly\">{SUB_ACCOUNT_ID_2}</var>",
      "accountName": "<var class=\"readonly\">{SUB_ACCOUNT_NAME_2}</var>",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    }
  ]
}

ตัวอย่างต่อไปนี้แสดงวิธีแสดงรายการบัญชีลูกค้าทั้งหมดของบัญชีขั้นสูง

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient.ListSubAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.ListSubAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to list all the subaccounts of an advanced account. */
public class ListSubAccountsSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static ListSubAccountsPagedResponse listSubAccounts(Config config) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    AccountsServiceSettings accountsServiceSettings =
        AccountsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates parent/provider to identify the advanced account from which to list all sub-accounts.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (AccountsServiceClient accountsServiceClient =
        AccountsServiceClient.create(accountsServiceSettings)) {

      // The parent has the format: accounts/{account}
      ListSubAccountsRequest request =
          ListSubAccountsRequest.newBuilder().setProvider(parent).build();
      System.out.println("Sending list subaccounts request:");

      ListSubAccountsPagedResponse response = accountsServiceClient.listSubAccounts(request);

      int count = 0;

      // Iterates over all rows in all pages and prints the datasource in each row.
      // Automatically uses the `nextPageToken` if returned to fetch all pages of data.
      for (Account account : response.iterateAll()) {
        System.out.println(account);
        count++;
      }
      System.out.print("The following count of accounts were returned: ");
      System.out.println(count);
      return response;
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    listSubAccounts(config);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ListSubAccountsRequest;

/**
 * This class demonstrates how to list all the subaccounts of an advanced account.
 */
class ListSubAccounts
{
    private static function getParent(string $accountId): string
    {
        return sprintf("accounts/%s", $accountId);
    }


    public static function listSubAccounts(array $config): void
    {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options config containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a client.
        $accountsServiceClient = new AccountsServiceClient($options);

        // Creates parent/provider to identify the advanced account from which
        //to list all accounts.
        $parent = self::getParent($config['accountId']);

        // Calls the API and catches and prints any network failures/errors.
        try {

            // The parent has the format: accounts/{account}
            $request = new ListSubAccountsRequest(['provider' => $parent]);
            print "Sending list subaccounts request:\n";

            $response = $accountsServiceClient->listSubAccounts($request);

            $count = 0;

            // Iterates over all rows in all pages and prints the datasource in each row.
            // Automatically uses the `nextPageToken` if returned to fetch all pages of data.
            foreach ($response->iterateAllElements() as $account) {
                print_r($account);
                $count++;
            }
            print "The following count of accounts were returned: ";
            print $count . PHP_EOL;
        } catch (ApiException $e) {
            print "An error has occured: \n";
            print $e->getMessage();
        }
    }

    public function callSample(): void
    {
        $config = Config::generateConfig();
        self::listSubAccounts($config);
    }
}

$sample = new ListSubAccounts();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import ListSubAccountsRequest


def get_parent(account_id):
  return f"accounts/{account_id}"


def list_sub_accounts(account_id: str):
  """Lists all the subaccounts of an advanced account."""

  # Get OAuth credentials.
  credentials = generate_user_credentials.main()

  # Create a client.
  client = AccountsServiceClient(credentials=credentials)

  # Get the parent advanced account ID.
  parent = get_parent(account_id)

  # Create the request.
  request = ListSubAccountsRequest(provider=parent)

  # Make the request and print the response.
  try:
    print("Sending list subaccounts request:")
    response = client.list_sub_accounts(request=request)

    count = 0
    for account in response:
      print(account)
      count += 1

    print(f"The following count of accounts were returned: {count}")
    return response

  except RuntimeError as e:
    print("An error has occured: ")
    print(e)
    raise


if __name__ == "__main__":
  _account_id = configuration.Configuration().read_merchant_info()
  list_sub_accounts(_account_id)

cURL

curl -X GET \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \

ลบบัญชีลูกค้า

หากไม่จำเป็นต้องจัดการบัญชีลูกค้าอีกต่อไป คุณสามารถลบบัญชีได้โดยใช้เมธอด accounts.delete

การดำเนินการตามวิธีนี้ต้องใช้สิทธิ์เข้าถึงระดับผู้ดูแลระบบในบัญชีที่ถูกลบ

ตัวอย่างคำขอมีดังนี้

DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}

หากทำสำเร็จ เนื้อหาคำตอบจะเป็นออบเจ็กต์ JSON ว่าง ซึ่งบ่งชี้ว่าบัญชีถูกลบแล้ว

ตัวอย่างต่อไปนี้แสดงวิธีลบบัญชีลูกค้า

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccountName;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.DeleteAccountRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to delete a given Merchant Center account. */
public class DeleteAccountSample {

  // This method can delete a standalone, advanced account or sub-account. If you delete an advanced
  // account,
  // all sub-accounts will also be deleted.
  // Admin user access is required to execute this method.

  public static void deleteAccount(Config config, String accountId) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    AccountsServiceSettings accountsServiceSettings =
        AccountsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates account name to identify the account.
    String name =
        AccountName.newBuilder()
            .setAccount(accountId)
            .build()
            .toString();

    // Calls the API.
    try (AccountsServiceClient accountsServiceClient =
        AccountsServiceClient.create(accountsServiceSettings)) {
      DeleteAccountRequest request =
          DeleteAccountRequest.newBuilder()
              .setName(name)
              // Optional. If set to true, the account will be deleted even if it has offers or
              // provides services to other accounts. Defaults to 'false'.
              .setForce(true)
              .build();

      System.out.println("Sending Delete Account request");
      accountsServiceClient.deleteAccount(request); // No response returned on success.
      System.out.println("Delete successful.");
    }
  }

  public static void deleteAccount(Config config) throws Exception {
    deleteAccount(config, config.getAccountId().toString());
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    deleteAccount(config);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\DeleteAccountRequest;


/**
 * This class demonstrates how to delete a given Merchant Center account.
 */
class DeleteAccount
{
    private static function getParent(string $accountId): string
    {
        return sprintf("accounts/%s", $accountId);
    }

    // This method can delete a standalone, advanced account or sub-account.
    // If you delete an advanced account, all sub-accounts will also be deleted.
    // Admin user access is required to execute this method.
    public static function deleteAccount(array $config): void
    {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options config containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a client.
        $accountsServiceClient = new AccountsServiceClient($options);


        // Gets the account ID from the config file.
        $accountId = $config['accountId'];

        // Creates account name to identify the account.
        $name = self::getParent($accountId);

        // Calls the API and catches and prints any network failures/errors.
        try {
            $request = new DeleteAccountRequest([
                'name' => $name,
                // Optional. If set to true, the account will be deleted even if it has offers or
                // provides services to other accounts. Defaults to 'false'.
                'force' => true,
            ]);

            print "Sending Delete Account request\n";
            $accountsServiceClient->deleteAccount($request); // No response returned on success.
            print "Delete successful.\n";
        } catch (ApiException $e) {
            print $e->getMessage();
        }
    }

    public function callSample(): void
    {
        $config = Config::generateConfig();
        self::deleteAccount($config);
    }
}

$sample = new DeleteAccount();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import DeleteAccountRequest


def get_parent(account_id):
  return f"accounts/{account_id}"


def delete_account(account_id: str):
  """Deletes a given Merchant Center account."""

  # Get OAuth credentials.
  credentials = generate_user_credentials.main()

  # Create a client.
  client = AccountsServiceClient(credentials=credentials)

  # Create the account name.
  name = get_parent(account_id)

  # Create the request.
  request = DeleteAccountRequest(name=name, force=True)

  # Make the request and print the response.
  try:
    print("Sending Delete Account request")
    client.delete_account(request=request)
    print("Delete successful.")
  except RuntimeError as e:
    print(e)
    raise


if __name__ == "__main__":
  _account_id = configuration.Configuration().read_merchant_info()
  delete_account(_account_id)

cURL

curl -X DELETE \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}?force=true" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \

ยอมรับข้อกำหนดในการให้บริการ

บัญชีลูกค้าจะรับช่วงข้อกำหนดในการให้บริการของ Merchant Center (TOS) ที่บัญชีขั้นสูงหลักลงนามไว้

อัปเดตข้อมูลทางธุรกิจ

คุณใช้ Merchant Accounts API เพื่อแก้ไขข้อมูลทางธุรกิจสำหรับบัญชีลูกค้าได้

  • หากต้องการดูข้อมูลทางธุรกิจของบัญชี ให้เรียกใช้ accounts.getBusinessInfo
  • หากต้องการแก้ไขข้อมูลทางธุรกิจของบัญชี โปรดโทรไปที่ accounts.updateBusinessInfo