POST/api/v4/posts

建立活動貼文

建立包含標題和開始/結束時間範圍的 EVENT 社群貼文,並發布至一個或多個地點所選的網站。

需要 API 金鑰。標頭格式與金鑰輪替請參閱驗證。

參數

請求主體

名稱類型必填說明
inputobject必填Wrapper object. Every field below is a property of `input`, the entire body must be nested under it.
input.postNamestring必填Internal name for the campaign (not shown to customers).
input.locationIdsarray of strings必填Base64-encoded location IDs to publish to (e.g. `TG9jYXRpb246MTgwMDI4OQ==`).
input.postTypestring必填Must be `EVENT`. One of EVENT, OFFER, ANNOUNCEMENT, COVID19, PRODUCT.
input.postSitesarray of strings必填Sites to publish to: `GOOGLE`, `FACEBOOK`.
input.postContextInfoobject選填Event details: `{ title, startDay, startTime, endDay, endTime }`. `title` is required by Google for events; `startDay`/`endDay` are dates, `startTime`/`endTime` are display strings like `10:00am`.
input.postMessagearray of objects選填Per-site body text: `{ site, message }`. One entry per site in `postSites`.
input.postScheduledDatesobject選填When to publish/expire the post itself: `{ startDatetime, endDatetime, removalSites }`. Distinct from the event's own dates in `postContextInfo`.
input.postCtaarray of objects選填Optional call-to-action per site: `{ site, type, url }`. `type` is one of BOOK, ORDER, SHOP, LEARN_MORE, SIGN_UP, GET_OFFER.
input.postMediaUrlarray of objects選填Optional media per site: `{ site, url, type }` where `type` is IMAGE or VIDEO.
input.clientMutationIdstring選填Optional client token returned unchanged in the response for correlation.

請求範例

可直接貼上的請求主體。請將預留位置 ID 與值換成您自己的。

Request body
{  "input": {    "postName": "Summer Sale Kickoff Event",    "locationIds": ["TG9jYXRpb246MTgwMDI4OQ=="],    "postType": "EVENT",    "postSites": ["GOOGLE"],    "postContextInfo": {      "title": "Summer Sale Kickoff",      "startDay": "2026-07-15",      "startTime": "10:00am",      "endDay": "2026-07-15",      "endTime": "06:00pm"    },    "postMessage": [      { "site": "GOOGLE", "message": "Join us for the Summer Sale kickoff, refreshments, giveaways, and up to 40% off in store." }    ],    "postCta": [      { "site": "GOOGLE", "type": "LEARN_MORE", "url": "https://jennyhome.example/summer-event" }    ],    "postMediaUrl": [      { "site": "GOOGLE", "url": "https://cdn.example.com/summer-event.jpg", "type": "IMAGE" }    ]  }}

回應

200Post accepted. Publishing runs asynchronously, the returned post starts as INPROGRESS.
Response
{  "data": {    "createSocialPost": {      "clientMutationId": null,      "success": true,      "errors": [],      "socialPost": {        "id": "U29jaWFsUG9zdDo0NDEyMw==",        "name": "Summer Sale Kickoff Event",        "status": "INPROGRESS",        "type": "EVENT",        "createdAt": "2026-07-01",        "scheduledStartDate": "2026-07-15",        "scheduledEndDate": "2026-07-15",        "sites": ["GOOGLE"],        "message": [          { "site": "GOOGLE", "message": "Join us for the Summer Sale kickoff, refreshments, giveaways, and up to 40% off in store." }        ],        "cta": [          { "type": { "value": "LEARN_MORE", "label": "Learn more" }, "url": "https://jennyhome.example/summer-event", "site": "GOOGLE", "tinyUrl": null }        ],        "contextInfo": {          "title": "Summer Sale Kickoff",          "startDay": "2026-07-15",          "startTime": "10:00am",          "endDay": "2026-07-15",          "endTime": "06:00pm",          "couponCode": null,          "redeemUrl": null,          "termsConditions": null,          "discount": null,          "locationType": null        },        "mediaUrl": [          { "url": "https://cdn.example.com/summer-event.jpg", "site": "GOOGLE", "type": "IMAGE" }        ],        "publishDetails": [          { "site": "GOOGLE", "status": "PUBLISHING", "createdDate": "2026-07-01", "submissionError": null }        ],        "postLinks": [],        "locationIds": [1800289]      }    }  }}
400Bad request, the body was not wrapped in `input` (error message: `Variable "$input" of required type "CreateSocialPostMutationInput!" was not provided`).
401Unauthenticated, missing or invalid API key.

建立活動貼文:這是一則包含日期、title 及開始/結束時間範圍的公告,會在 Google 上顯示為活動卡片。活動本身的時程設定於 postContextInfo(title、startDay、startTime、endDay、endTime);選填的 postScheduledDates 則控制貼文本身的發布與下架時間,通常涵蓋活動前的宣傳期間。

使用案例:宣傳店內活動。為 Jenny Home 發布「夏季特賣開跑」公告,將活動時段設為 7 月 15 日,並加入連往活動頁面的 LEARN_MORE CTA。設定 postType: "EVENT" 並填寫 postContextInfo.title,Google 會拒絕沒有標題的活動。此呼叫會傳回 status: INPROGRESS;請透過 GET /posts/{postId} 確認狀態變為 SUCCESS。

注意事項。

  • 請求主體必須包在 input 物件中:每個欄位都是 input 的屬性。未包裝的扁平主體會遭到拒絕,並傳回 HTTP 400(Variable "$input" of required type "CreateSocialPostMutationInput!" was not provided)。
  • postContextInfo 儲存活動日期;postScheduledDates 儲存發布日期。使用 postScheduledDates.startDatetime/endDatetime 提前排程貼文,並讓貼文在活動結束後自動到期。
  • 為 postSites 中的每個網站提供一筆 postMessage 項目。
  • 若要發布不含日期的純文字訊息,請使用 公告;若要發布優惠券/折扣,請使用 優惠。

寫入操作:未在正式帳戶上執行。此處顯示的請求與回應是根據 API 結構描述建構的;執行時,這項操作會將貼文發布至真實的 Google/Facebook 商家檔案。

Request
curl -X POST 'https://listingsapi.com/api/v4/posts' \  -H "Authorization: API $LISTINGSAPI_KEY" \  -H 'Content-Type: application/json' \  -d '{    "input": {      "postName": "Summer Sale Kickoff Event",      "locationIds": [        "TG9jYXRpb246MTgwMDI4OQ=="      ],      "postType": "EVENT",      "postSites": [        "GOOGLE"      ],      "postContextInfo": {        "title": "Summer Sale Kickoff",        "startDay": "2026-07-15",        "startTime": "10:00am",        "endDay": "2026-07-15",        "endTime": "06:00pm"      },      "postMessage": [        {          "site": "GOOGLE",          "message": "Join us for the Summer Sale kickoff, refreshments, giveaways, and up to 40% off in store."        }      ],      "postCta": [        {          "site": "GOOGLE",          "type": "LEARN_MORE",          "url": "https://jennyhome.example/summer-event"        }      ],      "postMediaUrl": [        {          "site": "GOOGLE",          "url": "https://cdn.example.com/summer-event.jpg",          "type": "IMAGE"        }      ]    }  }'