Skip to content

Call the platform API as a service account

Your backend calls the platform API (/api/...) as itself, with its application’s service account, never with a user’s token. The credential is an OAuth client id and secret (register an application); the SDKs exchange it for an access token and keep that token fresh.

The grant is plain OAuth 2.0 client credentials:

Terminal window
curl -s https://platform.example.com/oauth/token \
-d grant_type=client_credentials \
-d client_id="$FLOWCATALYST_CLIENT_ID" \
-d client_secret="$FLOWCATALYST_CLIENT_SECRET"
# {"access_token":"eyJ...","token_type":"Bearer","expires_in":3600,...}

The client may authenticate in the form body (client_secret_post) or with HTTP Basic (client_secret_basic). The token is an RS256 JWT with token_use=api, the account’s tier, roles, applications and, in scope, the permissions it was granted. It lives an hour by default (FC_JWT_ACCESS_TOKEN_TTL_SECS). There is no refresh token: ask again when it expires. Send it as Authorization: Bearer <token>.

The SDK clients fetch the token on first use, cache it, and renew it shortly before it expires.

import (
"github.com/flowcatalyst/go-sdk/auth"
"github.com/flowcatalyst/go-sdk/client"
)
cc := auth.NewClientCredentialsProvider(auth.ClientCredentialsConfig{
IssuerURL: os.Getenv("FLOWCATALYST_BASE_URL"), // token endpoint: <issuer>/oauth/token
ClientID: os.Getenv("FLOWCATALYST_CLIENT_ID"),
ClientSecret: os.Getenv("FLOWCATALYST_CLIENT_SECRET"),
})
c := client.New(os.Getenv("FLOWCATALYST_BASE_URL"), client.WithTokenProvider(cc.Token))
types, err := c.EventTypes().List(ctx, &client.EventTypeFilters{Application: "orders"})
if apiErr, ok := errors.AsType[*client.APIError](err); ok {
log.Printf("platform answered %d: %s", apiErr.StatusCode, apiErr.Body)
}

The provider renews 60 seconds before expiry (SafetyWindow) and is safe for concurrent use. The client makes up to 3 attempts, from a 100 ms delay that doubles (client.WithRetry); client.WithTimeout (30 s) bounds each attempt, not the whole call. It retries 408, 425, 429 and a connection that could not be made for every request. 500, 502, 503, 504 and a failure after the request was sent are retried only for a repeatable request (GET, HEAD, OPTIONS, PUT, DELETE, and a POST marked with PostRepeatable); any other request fails with *client.OutcomeUnknownError for 502, 503, 504 or a failure after sending, because the platform may have applied it. A 500 to a request that is not repeatable is returned as an *APIError.

Create one client per process and share it: each client holds its own token cache.

By default a token carries every permission the account’s roles grant. A process that only needs a few can ask for just those with scope on the token request; it gets the intersection with what the account holds, never more:

Terminal window
curl -s https://platform.example.com/oauth/token -d grant_type=client_credentials \
-d client_id=... -d client_secret=... \
-d scope="platform:application-service:event:create"

Go: ClientCredentialsConfig{Scopes: []string{...}}; fcdev outbox --scope. A request that asks only for permissions the account lacks is refused (invalid_scope). A leaked narrow token can do only what it was minted for.

The API answers errors as JSON with an error code and a message (see wire conventions and error codes):

Status Meaning Do
400 The request is invalid; error says why Fix the request; do not retry as is.
401 No valid token The SDK refetches once; if it persists, the credentials are wrong or revoked.
403 Authenticated, not allowed: a missing permission, another application’s resource, a client you cannot reach Do not retry. Check the account’s roles and application.
404 Not found, or outside what you may see (out-of-scope resources answer 404, not 403)
409 A conflict (a code in use, a stale version) Re-read and decide.
429 Rate limited The SDKs retry it with their own backoff; they do not wait for Retry-After. If you retry yourself, honour it.
502, 503, 504 A gateway could not say what became of the request The SDKs retry only a repeatable request (a GET, PUT or DELETE, or a POST you marked). Any other call fails with an outcome-unknown error: check whether it took effect before you send it again, or give it an idempotency key.
other 5xx The platform failed Retry with backoff yourself; most SDKs do not retry a 500.

Some writes record who asked in the audit trail even though your service account makes the call: platform configuration set, delete and revealSecret accept an on-behalf-of value (sent as X-On-Behalf-Of, at most 256 characters), honoured only from service accounts. It is recorded, not authorised: your application must have checked the person’s permission itself. See read configuration and secrets.

To try the API from your own machine against a shared test platform, use a developer credential rather than the application’s: a user with the platform:developer role can set a personal secret on their profile and use client credentials with their own principal id (prn_...) as the client_id. The token then holds exactly that person’s roles. See register an application.