POST
/api/v4/posts创建优惠帖子
创建包含优惠券、折扣和条款的 OFFER 社交帖子,并将其发布到一个或多个地点的所选站点。
参数
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| input | object | 必填 | Wrapper object. Every field below is a property of `input`, the entire body must be nested under it. |
| input.postName | string | 必填 | Internal name for the campaign (not shown to customers). |
| input.locationIds | array of strings | 必填 | Base64-encoded location IDs to publish to (e.g. `TG9jYXRpb246MTgwMDI4OQ==`). |
| input.postType | string | 必填 | Must be `OFFER`. One of EVENT, OFFER, ANNOUNCEMENT, COVID19, PRODUCT. |
| input.postSites | array of strings | 必填 | Sites to publish to: `GOOGLE`, `FACEBOOK`. |
| input.postContextInfo | object | 可选 | Offer details: `{ title, couponCode, discount, redeemUrl, termsConditions, startDay, endDay }`. `title` labels the offer; `startDay`/`endDay` bound its validity. |
| input.postMessage | array of objects | 可选 | Per-site body text: `{ site, message }`. One entry per site in `postSites`. |
| input.postScheduledDates | object | 可选 | When to publish/expire the post itself: `{ startDatetime, endDatetime, removalSites }`. Distinct from the offer validity in `postContextInfo`. |
| input.postCta | array of objects | 可选 | Optional call-to-action per site: `{ site, type, url }`. The `CTAType` enum accepts BOOK, ORDER, SHOP, LEARN_MORE, SIGN_UP, and GET_OFFER. There is no `REDEEM`. For offer posts, Google takes ORDER and Facebook takes GET_OFFER. |
| input.postMediaUrl | array of objects | 可选 | Optional media per site: `{ site, url, type }` where `type` is IMAGE or VIDEO. |
| input.clientMutationId | string | 可选 | Optional client token returned unchanged in the response for correlation. |
请求示例
可直接粘贴的请求体。请将占位 ID 和值替换为您自己的。
{ "input": { "postName": "Diwali 25% Off", "locationIds": ["TG9jYXRpb246MTgwMDI4OQ=="], "postType": "OFFER", "postSites": ["GOOGLE"], "postContextInfo": { "title": "25% off storewide", "couponCode": "DIWALI25", "discount": "25%", "redeemUrl": "https://jennyhome.example/diwali", "termsConditions": "Valid in-store only through July 6. Cannot be combined with other offers.", "startDay": "2026-06-22", "endDay": "2026-07-06" }, "postMessage": [ { "site": "GOOGLE", "message": "Celebrate with us: 25% off everything in store this festive week." } ], "postCta": [ { "site": "GOOGLE", "type": "GET_OFFER", "url": "https://jennyhome.example/diwali" } ], "postMediaUrl": [ { "site": "GOOGLE", "url": "https://cdn.example.com/diwali.jpg", "type": "IMAGE" } ] }}响应
200Post accepted. Publishing runs asynchronously, the returned post starts as INPROGRESS.
{ "data": { "createSocialPost": { "clientMutationId": null, "success": true, "errors": [], "socialPost": { "id": "U29jaWFsUG9zdDo0NDEyNA==", "name": "Diwali 25% Off", "status": "INPROGRESS", "type": "OFFER", "createdAt": "2026-06-20", "scheduledStartDate": "2026-06-22", "scheduledEndDate": "2026-07-06", "sites": ["GOOGLE"], "message": [ { "site": "GOOGLE", "message": "Celebrate with us: 25% off everything in store this festive week." } ], "cta": [ { "type": { "value": "GET_OFFER", "label": "Get offer" }, "url": "https://jennyhome.example/diwali", "site": "GOOGLE", "tinyUrl": null } ], "contextInfo": { "title": "25% off storewide", "couponCode": "DIWALI25", "discount": "25%", "redeemUrl": "https://jennyhome.example/diwali", "termsConditions": "Valid in-store only through July 6. Cannot be combined with other offers.", "startDay": "2026-06-22", "endDay": "2026-07-06", "startTime": null, "endTime": null, "locationType": null }, "mediaUrl": [ { "url": "https://cdn.example.com/diwali.jpg", "site": "GOOGLE", "type": "IMAGE" } ], "publishDetails": [ { "site": "GOOGLE", "status": "PUBLISHING", "createdDate": "2026-06-20", "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.
创建优惠帖子:包含优惠码、折扣、兑换链接和条款的促销卡片。优惠详情位于 postContextInfo 中(title、couponCode、discount、redeemUrl、termsConditions、startDay、endDay)。优惠适合搭配 GET_OFFER CTA。
使用场景:开展限时促销。为 Jenny Home 推出“排灯节优惠 25%”活动,有效期为 6 月 22 日至 7 月 6 日,并提供优惠码 DIWALI25 和兑换 URL。设置 postType: "OFFER",填写 postContextInfo,并添加 GET_OFFER CTA。调用返回 status: INPROGRESS;使用 GET /posts/{postId} 验证帖子是否已发布到各个站点,如果促销结束,则使用 DELETE /posts/{postId} 提前删除帖子。
注意事项。
- 请求体必须封装在
input对象中:每个字段都是input的属性。未封装的扁平请求体会被拒绝,并返回 HTTP 400(Variable "$input" of required type "CreateSocialPostMutationInput!" was not provided)。 postContextInfo.startDay/endDay限定优惠的有效期;如果您还希望独立安排帖子的发布时间和到期时间,请使用postScheduledDates。- 为
postSites中的每个站点提供一个postMessage条目。 - 普通更新请使用公告;有明确日期的活动请使用活动。
写入操作:未在实际账户中执行。所示请求和响应根据 API schema 构建;实际运行时,会向真实的 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": "Diwali 25% Off", "locationIds": [ "TG9jYXRpb246MTgwMDI4OQ==" ], "postType": "OFFER", "postSites": [ "GOOGLE" ], "postContextInfo": { "title": "25% off storewide", "couponCode": "DIWALI25", "discount": "25%", "redeemUrl": "https://jennyhome.example/diwali", "termsConditions": "Valid in-store only through July 6. Cannot be combined with other offers.", "startDay": "2026-06-22", "endDay": "2026-07-06" }, "postMessage": [ { "site": "GOOGLE", "message": "Celebrate with us: 25% off everything in store this festive week." } ], "postCta": [ { "site": "GOOGLE", "type": "GET_OFFER", "url": "https://jennyhome.example/diwali" } ], "postMediaUrl": [ { "site": "GOOGLE", "url": "https://cdn.example.com/diwali.jpg", "type": "IMAGE" } ] } }'