การอัปเดตสินค้าคงคลังแบบเพิ่ม v2

ส่วนนี้จะอธิบายวิธีส่งการอัปเดตข้อมูลสินค้าคงคลังที่มีความละเอียดอ่อนตามเวลาไปยัง Google Incremental Update API ช่วยให้คุณพุชข้อมูลอัปเดตและลบเอนทิตีในพื้นที่โฆษณาของแท็บทดลองใช้หรือเวอร์ชันที่ใช้งานจริงได้แบบเกือบเรียลไทม์

ฟังก์ชันการทำงานนี้มีไว้สำหรับข้อมูลอัปเดตที่คุณไม่สามารถคาดการณ์ได้เป็นหลัก เช่น การปิดร้านฉุกเฉิน ตามกฎแล้ว การเปลี่ยนแปลงที่ส่งผ่าน Incremental Update API ควรเป็นการเปลี่ยนแปลงที่ต้องเผยแพร่ภายในไม่เกิน 1 ชั่วโมง หากไม่จําเป็นต้องแสดงการเปลี่ยนแปลงทันที คุณก็ใช้การส่งผ่านข้อมูลแบบเป็นกลุ่มแทนได้ การอัปเดตเพิ่มเติมจะดำเนินการไม่เกิน 5 นาที

ข้อกำหนดเบื้องต้น

คุณต้องมีสิ่งต่อไปนี้ก่อนใช้การอัปเดตแบบเพิ่ม

  1. ระบบจะสร้างบัญชีบริการที่มีบทบาทผู้แก้ไขในโปรเจ็กต์การดําเนินการ โปรดดูรายละเอียดเพิ่มเติมที่หัวข้อสร้างและตั้งค่าโปรเจ็กต์
  2. ฟีดข้อมูลเวอร์ชันที่ใช้งานจริงหรือแซนด์บ็อกซ์ได้รับการโฮสต์และส่งผ่านข้อมูล ดูรายละเอียดเพิ่มเติมได้ที่การส่งผ่านข้อมูลแบบเป็นกลุ่ม
  3. (ไม่บังคับแต่แนะนำ) ติดตั้งไลบรารีไคลเอ็นต์ Google ในภาษาที่ต้องการเพื่ออำนวยความสะดวกในการใช้ OAuth 2.0 เมื่อเรียกใช้ API ตัวอย่างโค้ดที่รวมไว้ด้านล่างใช้ไลบรารีเหล่านี้ มิเช่นนั้น คุณจะต้องจัดการการแลกเปลี่ยนโทเค็นด้วยตนเองตามที่อธิบายไว้ในการใช้ OAuth 2.0 เพื่อเข้าถึง Google API

ปลายทาง

ในคำขอด้านล่าง ให้แทนที่ข้อมูลต่อไปนี้

  • PROJECT_ID: รหัสโปรเจ็กต์ Google Cloud ที่เชื่อมโยงกับโปรเจ็กต์ที่คุณสร้างขึ้นในส่วนสร้างและตั้งค่าโปรเจ็กต์
  • TYPE: ประเภทเอนทิตี (พร็อพเพอร์ตี้ @type) ของออบเจ็กต์ในฟีดข้อมูลที่ต้องการอัปเดต
  • ENTITY_ID (ลบปลายทางเท่านั้น): รหัสของเอนทิตีที่จะลบ อย่าลืมแปลงรหัส URL ของรหัสเอนทิตี
  • DELETE_TIME (ปลายทางการลบเท่านั้น): ช่องที่ไม่บังคับเพื่อระบุเวลาที่ลบเอนทิตีในระบบ (ค่าเริ่มต้นคือเมื่อได้รับคําขอ) ค่าเวลาต้องไม่เป็นเวลาในอนาคต เมื่อส่งเอนทิตีผ่านคอลที่เพิ่มขึ้น การกำหนดเวอร์ชันเอนทิตีจะใช้ช่อง delete_time ในกรณีที่มีการเรียกใช้การลบด้วย จัดรูปแบบค่านี้เป็น yyyy-mm-ddTHH:mm:ssZ

อัปเดตปลายทาง

หากต้องการแก้ไขเอนทิตี ให้ส่งคําขอ HTTP POST ไปยังปลายทางต่อไปนี้ และใส่เพย์โหลดของการอัปเดตและการเพิ่ม คุณอัปเดตเอนทิตีได้สูงสุด 1,000 รายการในการเรียก API ครั้งเดียว

https://actions.googleapis.com/v2/apps/PROJECT_ID/entities:batchPush

เช่น หากต้องการอัปเดตเอนทิตีในโปรเจ็กต์ที่มีรหัส "delivery-provider-id" ปลายทางจะเป็นดังนี้

https://actions.googleapis.com/v2/apps/delivery-provider-id/entities:batchpush

ลบปลายทาง

หากต้องการลบเอนทิตีในคลัง ให้ส่งคำขอ HTTP DELETE ไปยังปลายทางต่อไปนี้

https://actions.googleapis.com/v2/apps/PROJECT_ID/entities/TYPE/ENTITY_ID?entity.vertical=FOODORDERING&delete_time=DELETE_TIME

เช่น หากต้องการลบเอนทิตี "MenuSection" ที่มีรหัส "menuSection_122" จากโปรเจ็กต์ "delivery-provider-id" คุณจะต้องเรียกใช้ HTTP DELETE API ไปยัง

https://actions.googleapis.com/v2/apps/delivery-provider-id/entities/MenuSection/menuSection_122?entity.vertical=FOODORDERING

สภาพแวดล้อมของกล่องทราย

หากต้องการใช้ Incremental Update API ในพื้นที่โฆษณาใน Sandbox ให้ทําตามคําแนะนําในปลายทางด้านบน แต่ส่งคําขอไปยัง /v2/sandbox/apps/ แทน /v2/apps/

https://actions.googleapis.com/v2/sandbox/apps/PROJECT_ID/entities:batchPush
https://actions.googleapis.com/v2/sandbox/apps/PROJECT_ID/entities/TYPE/ENTITY_ID?entity.vertical=FOODORDERING&delete_time=DELETE_TIME

การอัปเดตเอนทิตี

คำขอ POST แต่ละรายการต้องมีพารามิเตอร์คำขอพร้อมกับเพย์โหลด JSON ที่มี Structured Data ของประเภทเอนทิตีที่แสดงอยู่ในสคีมาสินค้าคงคลัง

อัปเดตเพย์โหลด

JSON ควรปรากฏเหมือนกันกับในฟีดกลุ่ม โดยมีความแตกต่างดังต่อไปนี้

  • เนื้อหาของเพย์โหลดต้องมีขนาดไม่เกิน 5 MB ในทำนองเดียวกับฟีดกลุ่ม เราขอแนะนำให้คุณลบเว้นวรรคเพื่อใส่ข้อมูลได้มากขึ้น
  • โดยที่โฟลเดอร์มีดังนี้
{
  "requests": [
    {
      "entity": {
        "data":"ENTITY_DATA",
        "name": "apps/project_id>/entities/type/entity_id"
      },
      "update_time":"UPDATE_TIMESTAMP"
    },
  ],
  "vertical": "FOODORDERING"
}

ในเพย์โหลดด้านบน ให้แทนที่ข้อมูลต่อไปนี้

  • ENTITY_DATA: เอนทิตีในรูปแบบ JSON ที่แปลงเป็นสตริง ต้องส่งเอนทิตี JSON-LD เป็นสตริงในช่อง data
  • UPDATE_TIMESTAMP (ไม่บังคับ): การประทับเวลาเมื่อมีการอัปเดตเอนทิตีในระบบของคุณ ค่าเวลาต้องไม่เป็นเวลาในอนาคต การประทับเวลาเริ่มต้นคือเวลาที่ Google ได้รับคำขอ เมื่อส่งเอนทิตีผ่านคำขอแบบเพิ่ม การกำหนดเวอร์ชันเอนทิตีจะใช้ช่อง update_time ในกรณีที่มีคำขอเพิ่ม/อัปเดตด้วย

ตัวอย่าง

ตัวอย่างที่ 1: การอัปเดตร้านอาหาร

สมมติว่าคุณต้องอัปเดตหมายเลขโทรศัพท์ของร้านอาหารอย่างเร่งด่วน การอัปเดตของคุณมี JSON ของทั้งร้านอาหาร

ลองดูฟีดกลุ่มที่มีลักษณะดังต่อไปนี้

{
  "@type": "Restaurant",
  "@id": "restaurant12345",
  "name": "Some Restaurant",
  "url": "https://www.provider.com/somerestaurant",
  "telephone": "+16501234567",
  "streetAddress": "345 Spear St",
  "addressLocality": "San Francisco",
  "addressRegion": "CA",
  "postalCode": "94105",
  "addressCountry": "US",
  "latitude": 37.472842,
  "longitude": -122.217144
}

จากนั้นการอัปเดตแบบเพิ่มทีละรายการด้วย HTTP POST จะมีลักษณะดังนี้

POST v2/sandbox/apps/provider-project/entities:batchPush
Host: actions.googleapis.com
Content-Type: application/ld+json
{
  "requests": [
    {
      "entity": {
        "name": "apps/provider-project/entities/restaurant/restaurant12345",
        "data": {
          "@type": "Restaurant",
          "@id": "restaurant12345",
          "name": "Some Restaurant",
          "url": "https://www.provider.com/somerestaurant",
          "telephone": "+16501235555",
          "streetAddress": "345 Spear St",
          "addressLocality": "San Francisco",
          "addressRegion": "CA",
          "postalCode": "94105",
          "addressCountry": "US",
          "latitude": 37.472842,
          "longitude": -122.217144
        }
      }
    }
  "vertical": "FOODORDERING"
}

ตัวอย่างที่ 2: การอัปเดตร้านอาหารหลายแห่ง

หากต้องการอัปเดตเอนทิตีร้านอาหาร 2 รายการในการเรียก API ครั้งเดียว คำขอ HTTP POST จะเป็นดังนี้

POST v2/sandbox/apps/provider-project/entities:batchPush
Host: actions.googleapis.com
Content-Type: application/ld+json
{
  "requests": [
    {
      "entity": {
        "name": "apps/provider-project/entities/restaurant/restaurant12345",
        "data": {
          "@type": "Restaurant",
          "@id": "restaurant12345",
          "name": "Some Restaurant",
          "url": "https://www.provider.com/somerestaurant",
          "telephone": "+16501235555",
          "streetAddress": "345 Spear St",
          "addressLocality": "San Francisco",
          "addressRegion": "CA",
          "postalCode": "94105",
          "addressCountry": "US",
          "latitude": 37.472842,
          "longitude": -122.217144
        }
      }
    },
    {
      "entity": {
        "name": "apps/provider-project/entities/restaurant/restaurant123",
        "data": {
          "@type": "Restaurant",
          "@id": "restaurant123",
          "name": "Some Other Restaurant",
          "url": "https://www.provider.com/somerestaurant",
          "telephone": "+16501231235",
          "streetAddress": "385 Spear St",
          "addressLocality": "San Mateo",
          "addressRegion": "CA",
          "postalCode": "94115",
          "addressCountry": "US"
        }
      }
    }
  ]
  "vertical": "FOODORDERING"
}

ตัวอย่างที่ 3: การอัปเดตราคาของรายการเมนู

สมมติว่าคุณต้องเปลี่ยนราคาของรายการในเมนู เช่นเดียวกับตัวอย่างที่ 1 การอัปเดตต้องมี JSON สำหรับเอนทิตีระดับบนสุดทั้งหมด (เมนู) และฟีดใช้สคีมาพื้นที่โฆษณา v1

ลองดูฟีดกลุ่มที่มีลักษณะดังต่อไปนี้

{
  "@type": "MenuItemOffer",
  "@id": "menuitemoffer6680262",
  "sku": "offer-cola",
  "menuItemId": "menuitem896532",
  "price": 3.00,
  "priceCurrency": "USD"
}

การอัปเดตที่เพิ่มขึ้นผ่าน POST จะมีลักษณะดังนี้

POST v2/sandbox/apps/provider-project/entities:batchPush
Host: actions.googleapis.com
Content-Type: application/ld+json
{
  "requests": [
    {
      "entity": {
        "name": "apps/provider-project/entities/menuitemoffer/menuitemoffer6680262",
        "data": {
          "@type": "MenuItemOffer",
          "@id": "menuitemoffer6680262",
          "sku": "offer-cola",
          "menuItemId": "menuitem896532",
          "price": 1.00,
          "priceCurrency": "USD"
        },
        "vertical": "FOODORDERING"
      }
    }
  ]
  "vertical": "FOODORDERING"
}

การเพิ่มเอนทิตี

หากต้องการเพิ่มเอนทิตี ให้หลีกเลี่ยงการใช้การอัปเดตสินค้าคงคลัง แต่ให้ใช้กระบวนการฟีดกลุ่มตามที่อธิบายไว้สำหรับสคีมาสินค้าคงคลัง v2 แทน

การนำเอนทิตีออก

หากต้องการนําเอนทิตีระดับบนสุดออก ให้ใช้ปลายทางที่แก้ไขเล็กน้อย และ HTTP DELETE แทน HTTP POST ในคําขอ

การลบเอนทิตีระดับบนสุด

ลองพิจารณาสถานการณ์ที่คุณต้องการลบร้านอาหารในฟีด คุณต้องลบบริการและเมนูของช่องด้วย

ตัวอย่างปลายทางสำหรับเอนทิตีเมนูที่มีรหัส "provider/restaurant/menu/nr"

DELETE v2/apps/delivery-provider-id/entities/menu/provider%2Frestaurant%2Fmenu%2Fnr?entity.vertical=FOODORDERING
Host: actions.googleapis.com

ตัวอย่างปลายทางสำหรับเอนทิตีร้านอาหารที่มีรหัส "https://www.provider.com/restaurant/nr"

DELETE v2/apps/delivery-provider-id/entities/restaurant/provider%2Frestaurant%2Fnr?entity.vertical=FOODORDERING
Host: actions.googleapis.com

ตัวอย่างปลายทางสำหรับเอนทิตีบริการที่มีรหัส "https://www.provider.com/restaurant/service/nr"

DELETE v2/apps/delivery-provider-id/entities/service/provider%2Frestaurant%2Fservice%2Fnr?entity.vertical=FOODORDERING
Host: actions.googleapis.com
}

การนำเอนทิตีย่อยออก

อย่าใช้ HTTP DELETE เพื่อนำเอนทิตีย่อยภายในเอนทิตีระดับบนสุดออก เช่น รายการเมนูภายในเมนู แต่ให้ถือว่าการนำเอนทิตีย่อยออกเป็นการอัปเดตเอนทิตีระดับบนสุดซึ่งนำเอนทิตีย่อยออกจากรายการที่เกี่ยวข้องหรือ reverseReference

รหัสการตอบกลับของ API

การเรียกใช้ที่สำเร็จไม่ได้หมายความว่าฟีดถูกต้องหรือถูกต้อง เพียงแต่แสดงว่ามีการทำ API Call เท่านั้น การเรียกที่สำเร็จจะได้รับรหัสการตอบกลับ HTTP 200 พร้อมกับเนื้อหาการตอบกลับที่ว่างเปล่า

{}

หากดำเนินการไม่สำเร็จ โค้ดตอบกลับ HTTP จะไม่เท่ากับ 200 และเนื้อหาการตอบกลับจะระบุสิ่งที่ผิดพลาด

เช่น หากผู้ใช้ตั้งค่า "vertical" ในซองจดหมายเป็น FAKE_VERTICAL คุณจะได้รับข้อความด้านล่างนี้

{
  "error": {
    "code": 400,
    "message": "Invalid value at 'entity.vertical' (TYPE_ENUM), \"FAKE_VERTICAL\"",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "entity.vertical",
            "description": "Invalid value at 'entity.vertical' (TYPE_ENUM), \"FAKE_VERTICAL\""
          }
        ]
      }
    ]
  }
}

ตัวอย่างโค้ด

ด้านล่างนี้คือตัวอย่างวิธีใช้ Incremental Update API ในภาษาต่างๆ ตัวอย่างเหล่านี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google และสมมติว่าฟีดใช้สคีมาพื้นที่โฆษณา v1 ดูวิธีแก้ปัญหาอื่นๆ ได้ที่การใช้ OAuth 2.0 สำหรับแอปพลิเคชันที่มีการโต้ตอบระหว่างเซิร์ฟเวอร์กับเซิร์ฟเวอร์

การอัปเดตเอนทิตี

Node.js

โค้ดนี้ใช้ไลบรารีการให้สิทธิ์ของ Google สําหรับ Node.js

const {auth} = require('google-auth-library')
const request = require('request');
// The service account client secret file downloaded from the Google Cloud Console
const serviceAccountJson = require('./service-account.json')
// entity.json is a file that contains the entity data in json format
const entity = require('./entity.json')

const ENTITY_ID = 'your/entity/id'
const PROJECT_ID = 'type/your-project-id'

/**
 * Get the authorization token using a service account.
 */
async function getAuthToken() {
  let client = auth.fromJSON(serviceAccountJson)
  client.scopes = ['https://www.googleapis.com/auth/assistant']
  const tokens = await client.authorize()
  return tokens.access_token;
}

/**
 * Send an incremental update to update or add an entity
 */
async function updateEntity(entity) {
  const token = await getAuthToken()
  request.post({
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    url: `https://actions.googleapis.com/v2/apps/${PROJECT_ID}/entities:batchPush`,
    body: {
      requests: [
        {
          entity: {
            data: JSON.stringify(entity)
            name: `apps/${PROJECT_ID}/entities/${ENTITY_ID}`
          }
        }
      ],
      vertical: 'FOODORDERING'
    },
    json: true
  },
  (err, res, body) => {
    if (err) { return console.log(err); }
    console.log(`Response: ${JSON.stringify(res)}`)
  })
}

updateEntity(entity)

Python

โค้ดนี้ใช้ไลบรารีการให้สิทธิ์ของ Google สําหรับ Python

from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession
import json
import urllib

PROJECT_ID = 'your-project-id'
ENTITY_ID = 'type/your/entity/id'

ENDPOINT = 'https://actions.googleapis.com/v2/apps/%s/entities:batchPush' % (
    PROJECT_ID)

# service-account.json is the service account client secret file downloaded from the
# Google Cloud Console
credentials = service_account.Credentials.from_service_account_file(
    'service-account.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/assistant'])

authed_session = AuthorizedSession(scoped_credentials)

# Retrieving the entity
update_file = open("entity.json")  #JSON file containing entity data in json format.
data = update_file.read()

entity = {}
entity['data'] = data #entity JSON-LD serialized as string
entity['name'] = 'apps/%s/entities/%s' % (PROJECT_ID, urllib.quote(ENTITY_ID, '') )

# Populating the request
request = {}
request['entity'] = entity
requestArray = [request]

# Populating the payload
payload = {}
payload['requests'] = requestArray
payload['vertical'] = 'FOODORDERING'

response = authed_session.post(ENDPOINT, json=payload)

print(response.text) #if successful, will be '{}'

Java

โค้ดนี้ใช้ไลบรารีการให้สิทธิ์ของ Google สําหรับ Java

private static final String PROJECT_ID = "your-project-id";
private static final String ENTITY_ID = "type/your-entity-id";

/**
 * Get the authorization token using a service account.
 */
private static String getAuthToken() {
  InputStream serviceAccountFile =
      Example.class.getClassLoader().getResourceAsStream("service-account.json");
  ServiceAccountCredentials.Builder credentialsSimpleBuilder =
      ServiceAccountCredentials.fromStream(serviceAccountFile).toBuilder();
  credentialsSimpleBuilder.setScopes(ImmutableList.of("https://www.googleapis.com/auth/assistant"));
  AccessToken accessToken = credentialsSimpleBuilder.build().refreshAccessToken();
  return accessToken.getTokenValue();
}

/**
 * Send an incremental update to update or add an entity.
 * @param entityId The id of the entity to update.
 * @param entity the json of the entity to be updated.
 */
public void updateEntity(String entityId, JSONObject data) {
  String authToken = getAuthToken();
  String endpoint = String.format("https://actions.googleapis.com/v2/apps/%s/entities/:batchPush", PROJECT_ID);

  JSONObject entity = new JSONObject();
  entity.put("data", data.toString());
  entity.put("name", String.format("apps/%s/entities/%s", PROJECT_ID, URLEncoder.encode(ENTITY_ID, "UTF-8")));

  JSONObject request = new JSONObject();
  request.put("entity", entity);

  JSONArray requestArray = new JSONArray();
  requestArray.put(request);

  JSONObject payload = new JSONObject();
  payload.put("requests", requestArray);
  payload.put("vertical", FOODORDERING);

  // Execute POST request
  executePostRequest(endpoint, authToken, payload);
}

การนำเอนทิตีออก

Node.js

โค้ดนี้ใช้ไลบรารีการให้สิทธิ์ของ Google สําหรับ Node.js

const {auth} = require('google-auth-library')
const request = require('request');
// The service account client secret file downloaded from the Google Cloud Console
const serviceAccountJson = require('./service-account.json')
// entity.json is a file that contains the entity data in json format
const entity = require('./entity.json')

const ENTITY_ID = 'restaurant/http://www.provider.com/somerestaurant'
const PROJECT_ID = 'your-project-id'

/**
 * Get the authorization token using a service account.
 */
async function getAuthToken() {
  let client = auth.fromJSON(serviceAccountJson)
  client.scopes = ['https://www.googleapis.com/auth/assistant']
  const tokens = await client.authorize()
  return tokens.access_token;
}

/**
 * Send an incremental update to delete an entity
 */
async function deleteEntity(entityId) {
  const token = await getAuthToken()
  request.delete({
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    url: `https://actions.googleapis.com/v2/apps/${PROJECT_ID}/entities/${encodeURIComponent(entityId)}?entity.vertical=FOODORDERING`,
    body: {},
    json: true
  },
  (err, res, body) => {
    if (err) { return console.log(err); }
    console.log(`Response: ${JSON.stringify(res)}`)
  })
}

deleteEntity(ENTITY_ID)

Python

โค้ดนี้ใช้ไลบรารีการให้สิทธิ์ของ Google สําหรับ Python

from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession
import json
import urllib

# Service config
PROJECT_ID = 'your-project-id'
ENTITY_ID = 'restaurant/http://www.provider.com/somerestaurant'
DELETE_TIME = '2018-04-07T14:30:00-07:00'
ENDPOINT = 'https://actions.googleapis.com/v2/apps/%s/entities/%s?entity.vertical=FOODORDERING&delete_time=%s' % (
    PROJECT_ID, urllib.quote(ENTITY_ID, ''), urllib.quote(DELETE_TIME, ''))

# service-account.json is the service account client secret file downloaded from the
# Google Cloud Console
credentials = service_account.Credentials.from_service_account_file(
    'service-account.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/assistant'])

authed_session = AuthorizedSession(scoped_credentials)
response = authed_session.delete(ENDPOINT)

print(response.text) #if successful, will be '{}'

Java

โค้ดนี้ใช้ไลบรารีการให้สิทธิ์ของ Google สําหรับ Java

private static final String PROJECT_ID = "your-project-id";
private static final String ENTITY_ID = "restaurant/http://www.provider.com/somerestaurant";

/**
 * Get the authorization token using a service account.
 */
private static String getAuthToken() {
  InputStream serviceAccountFile = Example.class.getClassLoader().getResourceAsStream("service-account.json");
  ServiceAccountCredentials.Builder credentialsSimpleBuilder =
      ServiceAccountCredentials.fromStream(serviceAccountFile).toBuilder();
  credentialsSimpleBuilder.setScopes(ImmutableList.of("https://www.googleapis.com/auth/assistant"));
  AccessToken accessToken = credentialsSimpleBuilder.build().refreshAccessToken();
  return accessToken.getTokenValue();
}

/**
 * Send an incremental update to delete an entity.
 * @param entityId The id of the entity to delete.
 */
public void deleteEntity(String entityId) {
  String authToken = getAuthToken();
  String endpoint = String.format(
      "https://actions.googleapis.com/v2/apps/%s/entities/%s?entity.vertical=FOODORDERING",
      PROJECT_ID, URLEncoder.encode(entityId, "UTF-8"));
  // Execute DELETE request
  System.out.println(executeDeleteRequest(endpoint, authToken));
}

กรณีการใช้งาน

ตัวอย่างกรณีการใช้งานต่อไปนี้เป็นการอัปเดตที่เพิ่มขึ้น การอัปเดตฟีดทั้งหมด และเนื้อหาในระดับสูงในการเรียก API

สถานการณ์ เอนทิตีที่จะอัปเดต คำอธิบายและผล
การปิดใช้บริการ Service

คุณต้องปิดใช้บริการเนื่องจากเหตุผลที่ไม่คาดคิด

การอัปเดตแบบเพิ่ม: อัปเดตเอนทิตี Service ที่เป็นปัญหาโดยตั้งค่าพร็อพเพอร์ตี้ isDisabled เป็น true แต่ให้พร็อพเพอร์ตี้อื่นๆ เหมือนเดิม

ฟีดแบบสมบูรณ์: โปรดอัปเดตเอนทิตีจากฟีดแบบสมบูรณ์เพื่อตั้งค่า isDisabled เป็น true ก่อนการดึงข้อมูลครั้งถัดไปของ Google ไม่เช่นนั้นระบบจะเปิดใช้เอนทิตีอีกครั้ง

สินค้าบางรายการหมด MenuItemOffer การอัปเดตแบบเพิ่ม: ส่งเอนทิตี MenuItemOffer ที่รวมไว้โดยตั้งค่า inventoryLevel เป็น 0 สำหรับ MenuItem ที่ระบุ และข้อมูลอื่นๆ ทั้งหมดไม่มีการเปลี่ยนแปลง
การเปลี่ยนแปลงราคารายการในเมนู MenuItemOffer การอัปเดตเพิ่มเติม: ส่งเอนทิตี MenuItemOffer ที่รวมไว้โดยตั้งค่า price เป็นราคาที่อัปเดตแล้วสำหรับ MenuItem ที่ระบุ และข้อมูลอื่นๆ ทั้งหมดไม่มีการเปลี่ยนแปลง

เพิ่มเอนทิตีระดับบนสุดใหม่

ใช้กับเอนทิตีประเภท Menu, Restaurant และ Service เท่านั้น

Menu, Restaurant, Service

เช่น คุณต้องเพิ่มเมนูใหม่ลงในร้านอาหาร

ฟีดแบบสมบูรณ์: เพิ่มเอนทิตีในฟีดข้อมูลและรอการส่งผ่านข้อมูลเป็นกลุ่ม

ลบเอนทิตีระดับบนสุดอย่างถาวร

ใช้กับเอนทิตีประเภท Menu, Restaurant และ Service เท่านั้น

Menu, Restaurant, Service

การอัปเดตแบบเพิ่ม: ส่งการลบอย่างชัดแจ้ง

ฟีดแบบสมบูรณ์: โปรดนำเอนทิตีออกจากฟีดแบบสมบูรณ์ก่อนการดึงข้อมูลครั้งถัดไปของ Google มิเช่นนั้นระบบจะเพิ่มเอนทิตีนั้นอีกครั้ง

เพิ่มพื้นที่นำส่งใหม่ในServiceที่เฉพาะเจาะจง ServiceArea ฟีดที่เพิ่มขึ้น: ส่งเอนทิตี ServiceArea ที่เป็นปัญหาโดยเก็บช่องทั้งหมดไว้เหมือนเดิม เช่นเดียวกับที่คุณทำในฟีดแบบสมบูรณ์ โดยระบุพื้นที่การนำส่งใหม่ภายใน polygon, geoRadius หรือ postalCode
อัปเดตเวลาถึงโดยประมาณของการนำส่งใน Service ServiceHours ฟีดที่เพิ่มขึ้น: ส่ง ServiceHours เหมือนกับในฟีด ยกเว้น leadTimeMin ที่จะอัปเดตตาม
อัปเดตราคาการนำส่งใน Service Fee ฟีดที่เพิ่มขึ้น: ส่งการส่งโฆษณา Fee แบบสมบูรณ์โดยอัปเดต price
อัปเดตเวลานำส่งหรือเวลาให้บริการอาหารสำหรับซื้อกลับบ้านใน Service ServiceHours ฟีดที่เพิ่มขึ้น: ส่ง ServiceHours เหมือนกับในฟีด ยกเว้นพร็อพเพอร์ตี้ opens และ closes ที่จะอัปเดตตาม
Service (เปลี่ยนจำนวนเงินขั้นต่ำในการสั่งซื้อ) Fee ฟีดที่เพิ่มขึ้น: ส่ง Fee แบบสมบูรณ์ที่มี minPrice อัปเดต
ลบ MenuItem ถาวร Menu ฟีดที่เพิ่มขึ้น: ส่ง MenuItem เหมือนกับในฟีด แต่ให้ parentMenuSectionId ว่างเปล่า

SLO เกี่ยวกับเวลาในการประมวลผลสำหรับงานเป็นกลุ่มและการอัปเดตแบบเพิ่ม

ระบบจะประมวลผลเอนทิตีที่อัปเดตหรือลบผ่านกลุ่มภายใน 2 ชั่วโมงในโหมดพยายามอย่างเต็มที่ ส่วนเอนทิตีที่อัปเดตผ่านการอัปเดตแบบเพิ่มทีละรายการจะประมวลผลภายใน 5 นาที ระบบจะลบเอนทิตีที่ล้าสมัยใน 7 วัน

คุณส่งข้อมูลต่อไปนี้ให้ Google ได้

  • งานกลุ่มหลายรายการต่อวันเพื่อให้สินค้าคงคลังเป็นข้อมูลล่าสุด หรือ
  • งานแบบเป็นกลุ่ม 1 งานต่อวันและ API แบบเพิ่มเพื่ออัปเดตสินค้าคงคลังให้เป็นปัจจุบันอยู่เสมอ