to.co 首頁
開始使用

to.co API

讓您自己的軟體(例如網站、收銀系統或指令碼)讀取您在 to.co 上的公司資訊並保持更新。API 金鑰適用於 Pro 和 Grow 方案。

獲取 API 金鑰 路由

基礎 URL
https://api.to.co/v1/orgs/{host}
身份驗證
Authorization: Bearer toco_ak_…

獲取 API 金鑰

在 my.to.co 中開啟您的公司,選擇“API 金鑰”,然後選擇“建立金鑰”。為其命名,選擇權限範圍和到期時間(最長一年),然後複製:金鑰只顯示一次,我們只儲存其雜湊值。

在每個請求的 Authorization 標頭中傳送金鑰。金鑰僅對其所屬公司有效:訪問任何其他地址都會返回未找到。API 只接受金鑰,絕不接受瀏覽器會話。

呼叫示例

curl https://api.to.co/v1/orgs/mybusiness.uk.to.co \
  -H "Authorization: Bearer toco_ak_…"

權限範圍和方案

金鑰只能執行其權限範圍允許的操作,且僅限於每次請求時公司方案所包含的功能。讀取適用於 Pro 和 Grow;更改適用於 Grow。

權限範圍作用起始方案
company:readYour company details, services and locations.Pro
messages:readMessages from your contact form (not those held as spam).Pro
company:writeReplace your services, and change phone numbers and opening hours.Grow
posts:readThe posts you write on to.co, drafts included.Pro
posts:writeWrite, save, publish, unpublish and delete posts.Grow

路由

所有路由都位於基礎 URL 下,用您公司的 to.co 網址替換 {host},例如 mybusiness.uk.to.co。請求和響應均為 JSON。更改與在 my.to.co 中所做的更改經過相同的檢查、歷史記錄和重新發布流程,並記錄為由該金鑰所做。

路由作用權限範圍
GET /v1/orgs/{host}The company record, with its services and locations.company:read
GET /v1/orgs/{host}/servicesThe services, in order.company:read
GET /v1/orgs/{host}/locationsThe locations, with phones and opening hours.company:read
GET /v1/orgs/{host}/messagesContact form messages. Filter with ?status=new|read|replied|archived.messages:read
GET /v1/orgs/{host}/messages/{id}One message.messages:read
PATCH /v1/orgs/{host}Change the company phone numbers: JSON { "phones": … }.company:write
PUT /v1/orgs/{host}/servicesReplace the whole list of services, in order: JSON { "services": [ … ] }.company:write
PATCH /v1/orgs/{host}/locations/{location}Change a location: JSON with any of phones, normal_hours and special_hours. Every value is checked, and the answer carries the checks. The registered office comes from the register and cannot be changed.company:write
GET /v1/orgs/{host}/postsPosts written on to.co, newest change first, a page at a time: ?limit, ?state and ?cursor (next_cursor from the page before).posts:read
GET /v1/orgs/{host}/posts/{id}One post, its body as blocks, with its version as the ETag.posts:read
POST /v1/orgs/{host}/postsA new draft: JSON { "title", "standfirst", "body" }, or the body as text/markdown.posts:write
PATCH /v1/orgs/{host}/posts/{id}Save a post. Send the version you are changing as If-Match; JSON, or the body as text/markdown.posts:write
DELETE /v1/orgs/{host}/posts/{id}Move a post to the bin. The owner can restore it in my.to.co for 30 days.posts:write
POST /v1/orgs/{host}/posts/{id}/publishPublish the If-Match version. It is checked first, as when the owner publishes.posts:write
POST /v1/orgs/{host}/posts/{id}/unpublishTake a post off the page and back to a draft.posts:write

額度和限制

  • 每個請求消耗一個 API 額度,與您自己的 AI 助手呼叫您企業 MCP 伺服器共用同一月度額度:Pro 方案每家公司每月 5,000 個,Grow 方案 50,000 個。失敗的請求會退還其額度。額度在每月 1 日(UTC)重置,不收取超額費用。響應中包含 X-Credits-Limit、X-Credits-Remaining 和 X-Credits-Reset。
  • 每個金鑰每分鐘最多 120 個請求。
  • 每家公司每分鐘最多 60 次更改,與在 my.to.co 中和透過 MCP 所做的更改合併計算。

錯誤

出錯時返回 HTTP 狀態碼和 JSON:error(訊息)、code(以下之一)和 request_id。429 響應包含 Retry-After。

  • invalid_request (400) — The body or a query value is not valid; the message says which field.
  • cookie_not_accepted (400) — The request carried a browser session. This API takes an API key only.
  • if_match_required (400) — A post change without If-Match.
  • not_ready (400) — The post cannot be published yet; problems lists why.
  • image_unknown (400) — A post body shows an image the post does not have. A key cannot upload images.
  • invalid_key (401) — No key, or one that is unknown, revoked or expired.
  • insufficient_scope (403) — The key does not have the scope this route needs.
  • plan_required (403) — The company plan does not include this scope now; plan_needed names the plan that does.
  • insufficient_role (403) — The person who made the key no longer has the role for this; an owner makes a new key.
  • not_found (404) — Not found. A host other than the key's own company is always not found.
  • registered_office (409) — The registered office comes from the company register and cannot be changed with a key.
  • post_changed (409) — The post changed since the If-Match version. Read it again.
  • post_deleted (409) — The post is in the bin.
  • not_draft (409) — Only a draft can be scheduled.
  • slug_taken (409) — Another post already uses that address.
  • rate_limited (429) — Too many requests. Wait for Retry-After.
  • credits_exhausted (429) — This month's API credits are used. They start again on the first of next month; there are no overage charges.
  • credits_unavailable (503) — The API cannot count credits right now. Try again later.

Webhook

在 Grow 方案中,當發生變化時(例如收到新訊息或公司資訊更改),to.co 還可以向您自己的伺服器傳送已簽名的事件。請在 my.to.co 的“Webhook”中進行設定。

後續步驟

語言