تقديم الطلبات

يفترض هذا الدليل أنك عملت في دليل الخطوات الأولى وتم إعدادك لإجراء الطلبات المصرح بها.

بعد إعداد كلّ شيء، يمكنك إرسال طلبات إلى Google Content API for Shopping. توضّح نماذج الرموز التالية كيفية إرسال بعض الطلبات البسيطة:

  • أنشئ منتجًا.
  • الحصول على قائمة بالمنتجات
  • استرداد منتج معين من القائمة.
  • حدِّث سعر المنتج.

للحصول على قائمة كاملة بالطرق، يمكنك الاطّلاع على المستندات المرجعية.

لمزيد من المعلومات، راجِع صفحة أفضل الممارسات التي توضّح كيفية استخدام واجهة برمجة التطبيقات على أفضل وجه. وتشرح هذه الصفحة أيضًا سبب التوصية بالطلبات المجمّعة.

إذا كنت تواجه مشاكل في Content API، راجِع لوحة البيانات الخاصة بالحالة في Merchant Center للاطّلاع على حالات انقطاع الخدمة، وراجع صفحة المنتدى. إذا كنت لا تزال بحاجة إلى المساعدة، يمكنك التواصل مع فريق الدعم.

إنشاء منتج

يمكنك العثور على التفاصيل الكاملة حول جميع السمات التي يمكن أن تتوفر في المنتج في مواصفات المنتجات في الخلاصة. لإنشاء منتج ، استخدِم الرمز التالي:

البروتوكول

POST /content/v2.1/YOUR_MERCHANT_ID/products

{
  "offerId": "book123",
  "title": "A Tale of Two Cities",
  "description": "A classic novel about the French Revolution",
  "link": "http://my-book-shop.com/tale-of-two-cities.html",
  "imageLink": "http://my-book-shop.com/tale-of-two-cities.jpg",
  "contentLanguage": "en",
  "targetCountry": "GB",
  "feedLabel": "GB",
  "channel": "online",
  "availability": "in stock",
  "condition": "new",
  "googleProductCategory": "Media > Books",
  "gtin": "9780007350896",
  "price": {
    "value": "2.50",
    "currency": "GBP"
  },
  "shipping": [{
    "country": "GB",
    "service": "Standard shipping",
    "price": {
      "value": "0.99",
      "currency": "GBP"
    }
  }],
  "shippingWeight": {
    "value": "200",
    "unit": "grams"
  }
}

لغة Java

Product product = new Product();

product.setOfferId("book123");
product.setTitle("A Tale of Two Cities");
product.setDescription("A classic novel about the French Revolution");
product.setLink("http://my-book-shop.com/tale-of-two-cities.html");
product.setImageLink("http://my-book-shop.com/tale-of-two-cities.jpg");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
product.setAvailability("in stock");
product.setCondition("new");
product.setGoogleProductCategory("Media > Books");
product.setGtin("9780007350896");

Price price = new Price();
price.setValue("2.50");
price.setCurrency("GBP");
product.setPrice(price);

Price shippingPrice = new Price();
shippingPrice.setValue("0.99");
shippingPrice.setCurrency("GBP");

ProductShipping shipping = new ProductShipping();
shipping.setPrice(shippingPrice);
shipping.setCountry("GB");
shipping.setService("Standard shipping");

ArrayList shippingList = new ArrayList();
shippingList.add(shipping);
product.setShipping(shippingList);

Product result = service.products().insert(merchantId, product).execute();

لغة PHP

$product = new Google_Service_ShoppingContent_Product();
$product->setOfferId('book123');
$product->setTitle('A Tale of Two Cities');
$product->setDescription('A classic novel about the French Revolution');
$product->setLink('http://my-book-shop.com/tale-of-two-cities.html');
$product->setImageLink('http://my-book-shop.com/tale-of-two-cities.jpg');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
$product->setAvailability('in stock');
$product->setCondition('new');
$product->setGoogleProductCategory('Media > Books');
$product->setGtin('9780007350896');

$price = new Google_Service_ShoppingContent_Price();
$price->setValue('2.50');
$price->setCurrency('GBP');

$shipping_price = new Google_Service_ShoppingContent_Price();
$shipping_price->setValue('0.99');
$shipping_price->setCurrency('GBP');

$shipping = new Google_Service_ShoppingContent_ProductShipping();
$shipping->setPrice($shipping_price);
$shipping->setCountry('GB');
$shipping->setService('Standard shipping');

$shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
$shipping_weight->setValue(200);
$shipping_weight->setUnit('grams');

$product->setPrice($price);
$product->setShipping(array($shipping));
$product->setShippingWeight($shipping_weight);

$result = $service->products->insert($merchant_id, $product);

الحصول على قائمة بالمنتجات

للحصول على قائمة بالمنتجات، استخدِم الرمز التالي:

البروتوكول

GET /content/v2.1/YOUR_MERCHANT_ID/products

لغة Java

List productsList = service.products().list(merchantId);

ProductsListResponse page = productsList.execute();
while ((page.getResources() != null) && !page.getResources().isEmpty()) {
  for (Product product : page.getResources()) {
    System.out.printf("%s %s%n", product.getId(), product.getTitle());
  }

  if (page.getNextPageToken() == null) {
    break;
  }

  productsList.setPageToken(page.getNextPageToken());
  page = productsList.execute();
}

لغة PHP

$products = $service->products->listProducts($merchantId);
$parameters = array();
while (!empty($products->getResources()) {
  foreach ($products->getResources() as $product) {
    printf("%s %s\n", $product->getId(), $product->getTitle());
  }
  if (!empty($products->getNextPageToken()) {
    break;
  }
  $parameters['pageToken'] = $products->nextPageToken;
  $products = $service->products->listProducts($merchantId, $parameters);
}

استرداد منتج معين

لاسترداد منتج محدّد من القائمة، استخدِم الرمز التالي:

البروتوكول

GET /content/v2.1/YOUR_MERCHANT_ID/products/online:en:GB:book123

لغة Java

Product product = service.products()
    .get(merchantId, "online:en:GB:book123")
    .execute();
System.out.printf("%s %s\n", product.getId(), product.getTitle());

لغة PHP

$product = $service->products->get($merchant_id, 'online:en:GB:book123');
printf("%s %s\n", $product->getId(), $product->getTitle());

تحديث مدى توفّر المنتج على الإنترنت

يمكنك استخدام الخلاصات التكميلية في مورد "المنتجات" لتعديل بيانات المنتج على الإنترنت باستخدام الرمز التالي:

البروتوكول

POST /content/v2.1/YOUR_MERCHANT_ID/products?YOUR_SUPPLEMENTAL_FEED_ID

{
  "offerId": "book123",
  "contentLanguage": "en",
  "targetCountry": "GB",
  "feedLabel": "GB",
  "channel": "online",
  "availability": "out of stock"
}

لغة Java

Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");

// Optional Fields to Update
product.setAvailability("out of stock");

// Your unique supplemental feedId
feedId=123456789

Product result = service.products().insert(merchantId, product, feedId).execute();

لغة PHP

$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');

// Optional Fields to Update
$product->setAvailability('out of stock');

// Your unique supplemental feedId
$feedId=123456789

$result = $service->products->insert($merchant_id, $product, $feedId);

تعديل مدى توفّر المنتجات المحلية

يمكنك استخدام خدمة المنتجات المتوفرة محليًا لتعديل بيانات المنتجات المحلّية باستخدام الرمز التالي:

البروتوكول

POST /content/v2.1/YOUR_MERCHANT_ID/localinventory/online/products/online:en:GB:book123

{
  "availability": "out of stock"
}

لغة Java

Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");

// Optional Fields to Update
product.setAvailability("out of stock");

Product result = service.localinventory().insert(merchantId, product).execute();

لغة PHP

$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');

// Optional Fields to Update
$product->setAvailability('out of stock');

$result = $service->localinventory->insert($merchant_id, $product);