אפשר להשתמש ב-custombatch
כדי insert
, ב-get
או ב-delete
מוצרים מרובים בו-זמנית בקריאה אחת ל-API.
כדי לבצע קריאה לממשקי ה-API של אצווה בהתאמה אישית, צריך להשתמש בכתובת ה-URL הבאה:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
גוף הבקשה מכיל פרמטרים ספציפיים: batchId
, merchantID
ו-method
.
יש להשתמש ב-productId
רק אם מבצעים get או מחיקה. הערך productId
לא נדרש בקריאה ל-API של הוספה עבור custombatch
.
custombatch:insert
כתובת ה-URL של הבקשה הבאה משמשת ליצירת products.custombatch method=insert
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
כדי להוסיף את שני המוצרים החדשים, צריך לציין את השדה batchId
לכל מוצר, את merchantId
של המוכר שמורשה לבצע את הקריאה ל-API ואת השיטה insert
.
בדוגמה הבאה, ערכי batchId
הם 1111
ו-1112
בהתאמה, והם מזהים ייחודיים לכל מוצר. merchantId:
1234567
הוא המוכר שמורשה לבצע את הקריאה ל-API, והשיטה
היא get
, delete
או insert
.
insert
יוצר מוצר חדש. אם קיימים ערכים למאפיינים channel
, contentLanguage
, offerId
ו-feedLabel
לגבי
מוצר
מסוים, השיטה הזו מעדכנת את הרשומה ומחליפה את כל הנתונים מקריאות
ה-API הקודמות של המוצר.
הנה דוגמה של גוף JSON לinsert
שתי חולצות למסד הנתונים של Merchant Center באמצעות קריאה אחת ל-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"
]
}
}
]
}
קריאה מוצלחת ל-API מחזירה קוד HTTP 200
ותגובת JSON שכוללת את המוצרים שנוספו. הפורמט של ה-JSON לחזרה דומה לפורמט הבא:
{
"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"
]
}
}
]
}
custombatch:get
באמצעות כתובת ה-URL של הבקשה הבאה מתבצעת קריאה ל-products.custombatch
באמצעות method=get
:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
כדי לקבל מוצר, צריך לציין את השדה batchId
הייחודי למוצר של הקריאה ל-API, את הערך merchantId
של המוכר שמורשה לבצע את הקריאה ל-API, את השיטה get
ואת ה-productId
של המוצר שאוחזר.
בהמשך מופיעה דוגמה של גוף בקשת JSON לאחזור שני המוצרים שנוספו באמצעות הדוגמה הקודמת של custombatch:insert
, שצוינה באמצעות ערכי productId
שלהם. הערך batchId
ייחודי לכל פריט ברשימה:
{
"entries": [
{
"batchId": 1113,
"merchantId": 1234567,
"method": "get",
"productId": "online:en:US:1111111111"
},
{
"batchId": 1114,
"merchantId": 1234567,
"method": "get",
"productId": "online:en:US:2222222222"
}
]
}
הקריאה הזו מחזירה קוד HTTP 200
ואת גוף התגובה הבא:
{
"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"
]
}
}
]
}
custombatch:delete
כתובת ה-URL של הבקשה הבאה משמשת ליצירת products.custombatch
באמצעות method=delete
:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
כדי למחוק מוצר, צריך לציין את השדה batchId
שהוא ייחודי למוצר בקריאה הזו ל-API, את ה-merchantId
של המוכר שמורשה לבצע את הקריאה הזו ל-API, את השיטה delete
ואת ה-productId
של המוצר שנמחק.
{
"entries": [
{
"batchId": 1115,
"merchantId": 1234567,
"method": "delete",
"productId": "online:en:US:1111111111"
},
{
"batchId": 1116,
"merchantId": 1234567,
"method": "delete",
"productId": "online:en:US:2222222222"
}
]
}
הקריאה הזו מחזירה קוד HTTP 200
ואת ערכי batchId
של הפריטים שנמחקו:
{
"kind": "content#productsCustomBatchResponse",
"entries": [
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1115
},
{
"kind": "content#productsCustomBatchResponseEntry",
"batchId": 1116
}
]
}