你的第一則帖文

取得 API 金鑰

1. 檢查已連結的網絡

帖文會透過與門市連結的帳號送出。先列出這些帳號;如果缺少某個,請建立連結用的連結。

bash
curl https://api.sofia-post.com/api/v1/establishments/$ESTABLISHMENT_ID/accounts \
  -H "Authorization: Bearer $SOFIA_API_KEY"

2. 加入媒體

Instagram 和 TikTok 需要相片或影片。從公開的 https URL 匯入一個;Sofia 會將其下載到媒體庫並回傳它的 id。

bash
curl -X POST https://api.sofia-post.com/api/v1/media \
  -H "Authorization: Bearer $SOFIA_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"establishmentId":"'$ESTABLISHMENT_ID'","url":"https://images.example.com/tarte-tatin.jpg"}'

3. 試跑檢查

加上 ?dry_run=true:Sofia 會依據各網絡的實際規則和已連結的帳號逐一判斷,且不寫入任何內容。

bash
curl -X POST 'https://api.sofia-post.com/api/v1/posts?dry_run=true' \
  -H "Authorization: Bearer $SOFIA_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "establishmentId": "'$ESTABLISHMENT_ID'",
    "targets": [
      { "platform": "instagram", "text": "Tarte tatin du jour", "media": [{ "id": "'$MEDIA_ID'" }] },
      { "platform": "facebook", "text": "Tarte tatin du jour", "media": [{ "id": "'$MEDIA_ID'" }] }
    ]
  }'
json
{
  "status": "ready",
  "dryRun": true,
  "targets": [
    { "platform": "instagram", "accountId": "fecd0904-…", "handle": "sof_ia_officiel", "state": "ready" },
    { "platform": "facebook", "accountId": "a423b3a4-…", "handle": "Sofia post", "state": "ready" }
  ]
}

4. 發布

傳送相同的請求本文,拿掉 dry_run,並帶上 Idempotency-Key,這樣重試時絕不會重複發布。沒有 scheduledAt 時帖文會立即送出;帶上未來的 scheduledAt 則會排程發布。

bash
curl -X POST https://api.sofia-post.com/api/v1/posts \
  -H "Authorization: Bearer $SOFIA_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: $(uuidgen)" \
  -d @post.json

5. 追蹤

帖文先回傳 publishing,接著各網絡會變成帶永久連結的 published,或帶原因的 failed。用 GET /v1/posts/{id} 讀取,或註冊 webhook 來接收通知。

json
{
  "id": "efc578cc-ef79-40e9-876d-be1a33d3b8db",
  "status": "published",
  "targets": [
    {
      "platform": "instagram",
      "state": "published",
      "publishedAt": "2026-11-02T20:17:25.453Z",
      "permalink": "https://www.instagram.com/p/DfQJVPGFfb_/"
    }
  ]
}