Bạn có thể sử dụng custombatch
đến insert
, get
hoặc delete
nhiều sản phẩm cùng một lúc trong một lệnh gọi API.
Sử dụng URL yêu cầu sau đây để thực hiện lệnh gọi đến các API lô tuỳ chỉnh:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
Nội dung yêu cầu chứa các tham số cụ thể: batchId
, merchantID
và method
.
Chỉ sử dụng productId
nếu bạn đang thực thi một lệnh lấy hoặc xoá. Không bắt buộc phải có productId
trong lệnh gọi API chèn cho custombatch
.
gói tuỳ chỉnh:chèn
URL yêu cầu sau đây được dùng để tạo products.custombatch method=insert
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
Để chèn hai sản phẩm mới này, hãy chỉ định batchId
cho từng sản phẩm, merchantId
của người bán được uỷ quyền thực hiện lệnh gọi API và phương thức insert
.
Trong ví dụ sau, giá trị batchId
lần lượt là 1111
và 1112
và là giá trị nhận dạng duy nhất cho từng sản phẩm. merchantId:
1234567
là người bán được uỷ quyền thực hiện lệnh gọi API và phương thức là get
, delete
hoặc insert
.
insert
tạo ra một sản phẩm mới. Nếu có giá trị của các thuộc tính channel
, contentLanguage
, offerId
và feedLabel
của một sản phẩm nhất định, thì phương thức này sẽ cập nhật mục nhập và thay thế tất cả dữ liệu từ các lệnh gọi API trước đó cho sản phẩm.
Dưới đây là nội dung mẫu JSON cho insert
hai chiếc áo phông trong cơ sở dữ liệu Merchant Center bằng một lệnh gọi API:
{
"entries": [
{
"batchId": 1111,
"merchantId": 1234567,
"method": "insert",
"product": {
"kind": "content#product",
"offerId": "1111111111",
"title": "Google Tee Black",
"description": "The Black Google Tee is available in unisex sizing and
features a retail fit.",
"link": "http://my.site.com/blacktee/",
"imageLink": "https://shop.example.com/.../images/GGOEGXXX1100.jpg",
"contentLanguage": "en",
"targetCountry": "US",
"feedLabel": "US",
"channel": "online",
"ageGroup": "adult",
"availability": "in stock",
"availabilityDate": "2019-01-25T13:00:00-08:00",
"brand": "Google",
"color": "black",
"condition": "new",
"gender": "male",
"googleProductCategory": "1604",
"gtin": "608802531656",
"itemGroupId": "google_tee",
"mpn": "608802531656",
"price": {
"value": "21.99",
"currency": "USD"
},
"sizes": [
"Large"
],
"includedDestination": [
"Shopping"
]
}
},
{
"batchId": 1112,
"merchantId": 1234567,
"method": "insert",
"product": {
"kind": "content#product",
"offerId": "2222222222",
"title": "Google Tee Green",
"description": "100% cotton jersey fabric sets this Google t-shirt above
the crowd. Features the google logo across the chest. Unisex sizing.",
"link": "http://my.site.com/greentee/",
"imageLink": "https://shop.example.com/.../images/GGOEGXXX0906.jpg",
"contentLanguage": "en",
"targetCountry": "US",
"feedLabel": "US",
"channel": "online",
"ageGroup": "adult",
"availability": "in stock",
"availabilityDate": "2019-01-25T13:00:00-08:00",
"brand": "Google",
"color": "green",
"condition": "new",
"gender": "male",
"googleProductCategory": "1604",
"gtin": "608802531649",
"itemGroupId": "google_tee",
"mpn": "608802531649",
"price": {
"value": "21.99",
"currency": "USD"
},
"sizes": [
"Medium"
],
"includedDestination": [
"Shopping"
]
}
}
]
}
Lệnh gọi API thành công sẽ trả về mã HTTP 200
và phản hồi JSON có chứa các sản phẩm đã được chèn. Định dạng của JSON trả về tương tự như sau:
{
"kind": "content#productsCustomBatchResponse",
"entries": [
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1111,
"product": {
"kind": "content#product",
"id": "online:en:US:1111111111",
"offerId": "1111111111",
"title": "Google Tee Black",
"description": "The Black Google Tee is available in unisex sizing and
features a retail fit.",
"link": "http://my.site.com/blacktee/",
"imageLink": "https://shop.example.com/.../images/GGOEGXXX1100.jpg",
"contentLanguage": "en",
"targetCountry": "US",
"feedLabel": "US",
"channel": "online",
"ageGroup": "adult",
"availability": "in stock",
"availabilityDate": "2019-01-25T13:00:00-08:00",
"brand": "Google",
"color": "black",
"condition": "new",
"gender": "male",
"googleProductCategory": "1604",
"gtin": "608802531656",
"itemGroupId": "google_tee",
"mpn": "608802531656",
"price": {
"value": "21.99",
"currency": "USD"
},
"sizes": [
"Large"
],
"includedDestination": [
"Shopping"
]
}
},
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1112,
"product": {
"kind": "content#product",
"id": "online:en:US:2222222222",
"offerId": "2222222222",
"title": "Google Tee Green",
"description": "100% cotton jersey fabric sets this Google t-shirt above
the crowd. Features the google logo across the chest. Unisex sizing.",
"link": "http://my.site.com/greentee/",
"imageLink": "https://shop.example.com/.../images/GGOEGXXX0906.jpg",
"contentLanguage": "en",
"targetCountry": "US",
"feedLabel": "US",
"channel": "online",
"ageGroup": "adult",
"availability": "in stock",
"availabilityDate": "2019-01-25T13:00:00-08:00",
"brand": "Google",
"color": "green",
"condition": "new",
"gender": "male",
"googleProductCategory": "1604",
"gtin": "608802531649",
"itemGroupId": "google_tee",
"mpn": "608802531649",
"price": {
"value": "21.99",
"currency": "USD"
},
"sizes": [
"Medium"
],
"includedDestination": [
"Shopping"
]
}
}
]
}
gói tuỳ chỉnh:lấy
URL yêu cầu sau đây thực hiện lệnh gọi products.custombatch
với method=get
:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
Để nhận một sản phẩm, hãy chỉ định batchId
là duy nhất cho sản phẩm cho lệnh gọi API, merchantId
của người bán được uỷ quyền thực hiện lệnh gọi API, phương thức get
và productId
của sản phẩm đang được truy xuất.
Sau đây là nội dung yêu cầu JSON mẫu để truy xuất 2 sản phẩm được chèn bằng ví dụ custombatch:insert
trước đó, được chỉ định theo giá trị productId
của các sản phẩm đó. batchId
là duy nhất cho mỗi mục trong danh sách:
{
"entries": [
{
"batchId": 1113,
"merchantId": 1234567,
"method": "get",
"productId": "online:en:US:1111111111"
},
{
"batchId": 1114,
"merchantId": 1234567,
"method": "get",
"productId": "online:en:US:2222222222"
}
]
}
Lệnh gọi này trả về một mã HTTP 200
và nội dung phản hồi sau:
{
"kind": "content#productsCustomBatchResponse",
"entries": [
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1113,
"product": {
"kind": "content#product",
"id": "online:en:US:1111111111",
"offerId": "1111111111",
"title": "Google Tee Black",
"description": "The Black Google Tee is available in unisex sizing and features a retail fit.",
"link": "http://my.site.com/blacktee/",
"imageLink": "https://shop.example.com/.../images/GGOEGXXX1100.jpg",
"contentLanguage": "en",
"targetCountry": "US",
"feedLabel": "US",
"channel": "online",
"ageGroup": "adult",
"availability": "in stock",
"availabilityDate": "2019-01-25T13:00:00-08:00",
"brand": "Google",
"color": "black",
"condition": "new",
"gender": "male",
"googleProductCategory": "1604",
"gtin": "608802531656",
"itemGroupId": "google_tee",
"mpn": "608802531656",
"price": {
"value": "21.99",
"currency": "USD"
},
"sizes": [
"Large"
],
"includedDestination": [
"Shopping"
]
}
},
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1114,
"product": {
"kind": "content#product",
"id": "online:en:US:2222222222",
"offerId": "2222222222",
"title": "Google Tee Green",
"description": "100% cotton jersey fabric sets this Google t-shirt above the crowd.
Features the google logo across the chest. Unisex sizing.",
"link": "http://my.site.com/greentee/",
"imageLink": "https://shop.example.com/.../images/GGOEGXXX0906.jpg",
"contentLanguage": "en",
"targetCountry": "US",
"feedLabel": "US",
"channel": "online",
"ageGroup": "adult",
"availability": "in stock",
"availabilityDate": "2019-01-25T13:00:00-08:00",
"brand": "Google",
"color": "green",
"condition": "new",
"gender": "male",
"googleProductCategory": "1604",
"gtin": "608802531649",
"itemGroupId": "google_tee",
"mpn": "608802531649",
"price": {
"value": "21.99",
"currency": "USD"
},
"sizes": [
"Medium"
],
"includedDestination": [
"Shopping"
]
}
}
]
}
gói tuỳ chỉnh:xoá
URL yêu cầu sau đây được dùng để tạo products.custombatch
với method=delete
:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
Để xoá một sản phẩm, hãy chỉ định batchId
dành riêng cho sản phẩm trong lệnh gọi API này, merchantId
của người bán được uỷ quyền thực hiện lệnh gọi API này, phương thức delete
và productId
của sản phẩm đang bị xoá.
{
"entries": [
{
"batchId": 1115,
"merchantId": 1234567,
"method": "delete",
"productId": "online:en:US:1111111111"
},
{
"batchId": 1116,
"merchantId": 1234567,
"method": "delete",
"productId": "online:en:US:2222222222"
}
]
}
Lệnh gọi này trả về mã HTTP 200
và giá trị batchId
của các mục đã xoá:
{
"kind": "content#productsCustomBatchResponse",
"entries": [
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1115
},
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1116
}
]
}