to.co API
让您自己的软件(例如网站、收银系统或脚本)读取您在 to.co 上的公司信息并保持更新。API 密钥适用于 Pro 和 Grow 套餐。
- 基础 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:read | Your company details, services and locations. | Pro |
messages:read | Messages from your contact form (not those held as spam). | Pro |
company:write | Replace your services, and change phone numbers and opening hours. | Grow |
posts:read | The posts you write on to.co, drafts included. | Pro |
posts:write | Write, 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}/services | The services, in order. | company:read |
GET /v1/orgs/{host}/locations | The locations, with phones and opening hours. | company:read |
GET /v1/orgs/{host}/messages | Contact 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}/services | Replace 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}/posts | Posts 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}/posts | A 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}/publish | Publish the If-Match version. It is checked first, as when the owner publishes. | posts:write |
POST /v1/orgs/{host}/posts/{id}/unpublish | Take 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”中进行设置。