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