POST/api/v4/locations/photos

将照片上传到地点

通过公开图片 URL 或引用媒体库中已有的文件,将媒体附加到地点。

需要 API 密钥。请求头格式和密钥轮换请参阅身份验证。

参数

请求体

标记为必填的嵌套字段仅在您发送其父字段时适用。如果父字段为可选且您省略了它,其必填子字段不适用。

名称类型必填描述
input.locationIdstring必填The location's Base64-encoded Relay ID to attach media to.
input.photosarray of objects必填Images to attach. `photo` is the only required key on each item.
input.photos[].photostring必填A publicly accessible JPEG or PNG URL that Listings API fetches and stores. The field is named `photo`, not `url`.
input.photos[].typestring可选Which slot the image fills: `LOGO`, `COVER`, or `ADDITIONAL`. Defaults to an additional photo.
input.photos[].starredboolean可选Star the photo as it is attached, instead of a follow-up call to the star endpoint. Only additional photos can be starred, at most 4 per location.
input.photos[].sourcestring可选Free-text label recording where the image came from.

请求示例

可直接粘贴的请求体。请将占位 ID 和值替换为您自己的。

Request body
{  "input": {    "locationId": "TG9jYXRpb246MTgwMDI4OQ==",    "photos": [      { "photo": "https://cdn.example.com/jenny-home/logo.png", "type": "LOGO" },      { "photo": "https://cdn.example.com/jenny-home/storefront.jpg", "type": "ADDITIONAL" }    ]  }}

响应

200Photos attached inline. Returns the created photo records; `errors` is null on success and `request` is empty because nothing was queued.
Response
{  "data": {    "addLocationPhotos": {      "clientMutationId": null,      "success": true,      "request": {},      "photos": [        {          "id": "TWVkaWFGaWxlOjU4Nzg5MzE=",          "databaseId": 5878931,          "url": "https://sy-media-store.s3-us-west-2.amazonaws.com/f868bb3f/59c670a3/f47d62a6.png",          "thumbnailUrl": "https://sy-media-store.s3-us-west-2.amazonaws.com/f868bb3f/59c670a3/thumbnail_f47d62a6.png",          "type": "LOGO",          "starred": false        },        {          "id": "TWVkaWFGaWxlOjU4Nzg5MzI=",          "databaseId": 5878932,          "url": "https://sy-media-store.s3-us-west-2.amazonaws.com/f868bb3f/59c670a3/ef4ffb12.jpg",          "thumbnailUrl": "https://sy-media-store.s3-us-west-2.amazonaws.com/f868bb3f/59c670a3/thumbnail_ef4ffb12.jpg",          "type": "ADDITIONAL",          "starred": false        }      ],      "errors": null    }  }}
401Unauthenticated, missing or invalid API key.

将一张或多张图片附加到地点。请提供一个 photos 数组,其中每项至少包含 photo,即 Listings API 用于获取并存储图片的公开图片 URL。locationId 和非空的 photos 数组始终为必填项。

成功响应的两种形式

小批量图片会在调用中直接上传:photos 包含已完成上传的媒体,request 为空对象,如上面的示例所示。大批量图片则会进入队列,同一个 200 如下所示:

JSON
{  "data": {    "addLocationPhotos": {      "clientMutationId": null,      "success": true,      "request": {        "requestId": "e6c2d9d9-9a18-4015-88cf-9a4e19a6f49a",        "status": "PROCCESSING"      },      "photos": [],      "errors": null    }  }}

这两种情况都表示成功,因此请根据 request.requestId 是否存在来处理响应,不要假定 photos 中有数据。

URL 字段是 photo。不是 url,也不是 image。除此之外,每项还接受可选的 type(LOGO、COVER 或 ADDITIONAL)、starred 和 source;对于合作伙伴集成,也接受 publisherOverride 和 partnerMediaId。返回的照片没有 caption 字段。

使用场景:为新地点添加初始图片。创建“Jenny Home”等地点后,立即在一次调用中通过 URL POST 其标志和店面照片。响应会返回每张新照片的 id,稍后可将其传给加星标端点和移除端点。

使用场景:在多个地点复用已批准的素材。在多个地点的 photos 数组中引用同一个托管图片 URL,使每个地点共享同一份源素材。

注意事项。

  • 图片必须为 JPEG 或 PNG 格式。发布平台的大小规则按类别适用(通常下限约为 10 KB,上限为几 MB)。
  • 大批量图片会异步处理。当批量大小超过服务器端设定的阈值时,调用会将任务加入队列,而不是直接上传:photos 返回为空,并设置 request.requestId。使用该 id 轮询 GET /locations/photos/requests/{requestId} 以跟踪完成情况。该阈值由服务器端配置,因此应将其理解为“大批量图片可能会进入队列”,而不是一个固定数字,并根据 request.requestId 是否存在来选择处理分支。
  • 不要根据 request.status 选择处理分支。在进入队列的响应中,它是字符串字面量 PROCCESSING,其拼写与轮询端点针对同一任务报告的 PROCESSING 不同。request.requestId 是否存在才是可靠的判断依据。
  • 如果传入 starred: true 导致星标照片数量超过允许的 4 张,整个调用将失败并返回 SY15012。此检查会将该地点已有的星标照片与本次请求中的星标项合并计数。
  • 每个地点只保留一张标志图片和一张封面图片;重新上传任一类别的图片都会替换该类别的现有图片。
  • 如果您希望将图片用作标志或封面,请显式设置 type。如果未设置,图片将作为附加照片存储。
Request
curl -X POST 'https://listingsapi.com/api/v4/locations/photos' \  -H "Authorization: API $LISTINGSAPI_KEY" \  -H 'Content-Type: application/json' \  -d '{    "input": {      "locationId": "TG9jYXRpb246MTgwMDI4OQ==",      "photos": [        {          "photo": "https://cdn.example.com/jenny-home/logo.png",          "type": "LOGO"        },        {          "photo": "https://cdn.example.com/jenny-home/storefront.jpg",          "type": "ADDITIONAL"        }      ]    }  }'