요청 수행

이 가이드에서는 시작 가이드를 살펴보고 승인된 요청을 받도록 설정했다고 가정합니다.

모든 설정을 완료하면 Google Content API for Shopping으로 요청을 보낼 수 있습니다. 다음 코드 샘플은 몇 가지 간단한 요청을 보내는 방법을 보여줍니다.

  • 제품을 만듭니다.
  • 제품 목록을 가져옵니다.
  • 목록에서 특정 제품을 검색합니다.
  • 제품 가격을 업데이트합니다.

전체 메서드 목록은 참조 문서를 확인하세요.

자세한 내용은 API 사용 방법을 설명하는 권장사항 페이지를 참조하세요. 이 페이지에서는 일괄 요청이 권장되는 이유도 설명합니다.

Content API에 문제가 있는 경우 판매자 센터 상태 대시보드의 서비스 중단 및 포럼 페이지를 확인하세요. 도움이 더 필요하면 지원팀에 문의하세요.

제품 만들기

제품 피드 사양에서 제품에 포함될 수 있는 모든 속성의 전체 세부정보를 확인할 수 있습니다. 제품을 생성하려면 다음 코드를 사용합니다.

프로토콜

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"
  }
}

자바

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

자바

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

자바

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"
}

자바

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"
}

자바

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);