你的第一条帖子

获取 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_/"
    }
  ]
}