Tokens and expiry
A partner API token proves that a shop member approved your app. If it leaks, someone else can read that shop’s data. Follow these rules.
Lifetimes
| Token | Lifetime | Use |
|---|---|---|
| Access token | 15 minutes from issue | Send it as Authorization: Bearer on API calls |
| Refresh token | 90 days from issue | Exchange it for new tokens when the access token expires |
Refresh tokens rotate: every refresh returns a new one. Use the new token for later refreshes. Regular refreshes keep the connection working past 90 days. Use the recovery procedure below only when the refresh response was lost.
Refreshing
const response = await fetch(
"https://api.toreca-cloud.com/api/auth/oauth2/token",
{
method: "POST",
headers: {
Authorization: "Basic " + basicCredentials,
"Content-Type": "application/x-www-form-urlencoded",
"X-Toreca-Refresh-Recovery": "1",
},
body: new URLSearchParams({
grant_type: "refresh_token",
refresh_token: storedRefreshToken,
resource: "https://api.toreca-cloud.com/partner/v1",
}),
},
);
const next = await response.json();
if (!response.ok) {
// For refresh_superseded, reload the latest stored token.
// invalid_grant needs authorization again. Never log token/error bodies.
throw new Error("Token refresh failed");
}
// Save next.access_token and next.refresh_token together
- When the API answers
401, refresh and retry once. - Serialize refreshes through saving, one at a time per connection.
- Save the new access and refresh tokens together as soon as you receive them.
- If refreshing fails with
invalid_grant, ask a shop member to approve again.
Recovering a lost refresh response
Send X-Toreca-Refresh-Recovery: 1 when refreshing to enable recovery for a confidential partner API client. The connection must remain active. This does not apply to MCP or another resource’s tokens.
- After a lost connection or failed save, retry the same refresh token, client authentication,
resource,scopeand header. - If the successor token has not been refreshed again, the same token response is returned. Save both tokens together.
refresh_supersededmeans that successor has itself been refreshed. Reload your latest stored token. Do not let an old worker overwrite newer stored credentials. If the latest value is lost, authorize again.
Recovery does not bypass expiry, revocation, disconnection or lost permissions. Do not keep retrying invalid_grant; check the connection and authorization.
Storing tokens
- Keep tokens and the client secret on your server only. Never put them in a browser, a mobile app or a static site’s JavaScript.
- Encrypt them at rest and limit who and what can read them.
- Keep tokens out of logs, error reports and analytics.
- If the client secret may have leaked, ask the shop admin to regenerate it (“Regenerate secret”). The old secret stops working at once.
When the connection stops
The API refuses calls in these cases even with an unexpired token.
| Situation | Response |
|---|---|
| The shop revoked the connection | 403 connection_revoked |
| The shop or Toreca Cloud paused the app | 403 client_disabled |
| The approving member left or lost a needed permission | 403 forbidden |
| The token lacks the needed scope | 403 insufficient_scope |
To disconnect from your side, call DELETE /partner/v1/connection. It also revokes every refresh token your app holds for that shop.

