本頁面說明如何使用 Merchant API 建立 Merchant Center 帳戶,並上傳範例產品。
事前準備
在 Google Cloud 專案中啟用 Merchant API。
如果 API 整合功能是在 AppScript 中使用 Shopping Content Service,系統會建立預設的 Google Cloud 專案,並自動啟用 Merchant API 服務。不過,您仍須先完成一次性開發人員註冊,才能使用 Merchant API。詳情請參閱「在 Apps Script 中使用 Merchant API 服務」。
建立帳戶
如要使用 Merchant API,你必須擁有 Merchant Center 帳戶。如要建立 Merchant Center 帳戶,請參閱「開始使用 Merchant Center」。
註冊成為開發人員
如要使用 Merchant API,請按照下列步驟,透過開發人員註冊方法連結 Merchant Center 帳戶和 Google Cloud 專案:
連結 Merchant Center 和 Google Cloud 專案:系統會自動核准連結,因為呼叫者擁有來自 Google Cloud 專案的有效存取權杖或 API 金鑰,而且是 Merchant Center 帳戶的授權使用者。
將 API 開發人員使用者新增至 Merchant Center 帳戶:註冊 API 會將 API 開發人員使用者新增至 Merchant Center 帳戶。如果使用者已存在,系統會授予新的存取類型。如果是新使用者,他們會收到 Merchant Center 電子郵件邀請。
建議您使用 accounts.users.create
方法新增其他或備用 API 開發人員,確保即使有人離開貴機構或遭到刪除,您仍可擁有有效的開發人員註冊。
註冊後,您可以使用 GetDeveloperRegistration
查看註冊狀態,或使用 UnregisterGCP
取消註冊。
註冊電話號碼為
POST https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/developerRegistration:registerGcp
{
developer_email:"example-email@example.com"
}
要求成功執行後,您應該會收到以下回應:
{
"developerRegistration": {
"name": "accounts/ACCOUNT_ID/developerRegistration",
"gcpIds": ["GOOGLE_CLOUD_PROJECT_ID"]
}
}
註冊 API 開發人員後,您可以使用 accounts.users.patch
方法授予他們其他角色,例如 STANDARD
和 ADMIN
。
取得帳戶 ID
您可以使用 accounts.list
方法取得帳戶 ID。
您可以使用 Google APIs Explorer 執行 Merchant API 要求。API Explorer 會使用 Google OAuth 2.0 進行驗證。執行要求前,請務必勾選「Google OAuth 2.0」核取方塊。
如要使用 OAuth 2.0 進行驗證,請登入 Google 帳戶,然後登入 API Explorer。您也必須允許 API Explorer 管理產品資訊和帳戶。
以下要求說明如何擷取帳戶 ID:
GET https://merchantapi.googleapis.com/accounts/v1beta/accounts
或
GET https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}
要求成功執行後,您會看到下列回應:
{
"accounts": [
{
"name": "{ACCOUNT_NAME}",
"accountId": "{ACCOUNT_ID}",
"accountName": "{ACCOUNT_DISPLAY_NAME}",
"timeZone": {
"id": "America/Los_Angeles"
},
"languageCode": "en-US"
}
]
}
複製 {ACCOUNT_ID}
,因為您需要這項資訊才能執行其他要求。
建立主要產品資料來源
如要插入產品,必須有主要產品資料來源。下列要求顯示如何建立資料來源,以便將產品插入帳戶:
POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources HTTP/1.1
{
"primaryProductDataSource": {
"channel": "ONLINE_PRODUCTS",
"contentLanguage": "en",
"countries": [
"US"
],
"feedLabel": "US"
},
"name": "primary-data-source",
"displayName": "Primary Products Data Source"
}
將 {ACCOUNT_ID} 替換為你建立的 Merchant Center 帳戶 ID。
成功執行這項要求後,您會看到以下回應:
{
"name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
"dataSourceId": "{DATASOURCE_ID}",
"displayName": "Primary Products Data Source",
"primaryProductDataSource": {
"channel": "ONLINE_PRODUCTS",
"feedLabel": "US",
"contentLanguage": "en",
"countries": [
"US"
],
"defaultRule": {
"takeFromDataSources": [
{
"self": true
}
]
}
},
"input": "API"
}
複製 name
欄位的值,因為您需要這個值才能插入產品。
建立資料來源後,需要幾分鐘才能插入產品。
你可以在 Merchant Center 使用者介面中查看這個資料來源。詳情請參閱「如何找到『資料來源』分頁」。
插入一項產品
如要在帳戶中插入範例產品,請執行下列要求:
POST https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs:insert?dataSource={DATASOURCE_NAME} HTTP/1.1
{
"channel": "ONLINE",
"contentLanguage": "en",
"feedLabel": "US",
"name": "Red T-shirt",
"attributes": {
"gender": "Male",
"brand": "New brand"
},
"offerId": "tshirt-123"
}
將 {DATASOURCE_NAME} 替換為先前複製的值。
成功執行這項要求後,您會看到以下回應:
{
"name": "accounts/{ACCOUNT_ID}/productInputs/online~en~US~tshirt-123",
"product": "accounts/{ACCOUNT_ID}/products/online~en~US~tshirt-123",
"channel": "ONLINE",
"offerId": "tshirt-123",
"contentLanguage": "en",
"feedLabel": "US",
"attributes": {
"brand": "New brand",
"gender": "Male"
}
}
新建立的產品 ID 為 online~en~US~tshirt-123
。您可以使用 accounts.products.get
方法擷取這項產品的詳細資料。你也可以使用 Merchant Center 使用者介面查看這項產品。