شما میتوانید custombatch برای insert ، get یا delete چندین محصول به طور همزمان در یک فراخوانی API استفاده کنید.

برای فراخوانی APIهای دستهای سفارشی، از URL درخواست زیر استفاده کنید:
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
بدنه درخواست شامل پارامترهای خاصی است: batchId ، merchantID و یک method .
فقط در صورت اجرای دستور get یا delete productId استفاده کنید. در فراخوانی API درج برای custombatch نیازی به productId نیست.
دسته سفارشی: درج
آدرس درخواست زیر برای ایجاد یک 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 دو تیشرت در پایگاه داده مرکز بازرگانان با استفاده از یک فراخوانی 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:دریافت
آدرس درخواست زیر، فراخوانی 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:حذف
آدرس درخواست زیر برای ساخت یک 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
}
]
}