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 token
Section titled “The token”The grant is plain OAuth 2.0 client credentials:
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>.
Use an SDK client
Section titled “Use an SDK client”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.
var client = FlowCatalystClient.builder() .baseUrl(System.getenv("FLOWCATALYST_BASE_URL")) .clientCredentials(System.getenv("FLOWCATALYST_CLIENT_ID"), System.getenv("FLOWCATALYST_CLIENT_SECRET")) .build();
try { var eventTypes = client.eventTypes().list(null);} catch (FlowCatalystException e) { switch (e.error()) { case SdkError.NotFound nf -> handleMissing(); case SdkError.RateLimited rl -> backOff(rl.retryAfter()); default -> throw e; }}Tokens are cached with a 60-second buffer and renewed single-flight. Retries use exponential
backoff from 100 ms, up to 3 retries after the first request. 408, 429 and a connection that
could not be made are retried for every request; 502, 503, 504 and a failure after the
request was sent are retried only for a repeatable request (GET, HEAD, OPTIONS, PUT, DELETE, or
a call marked with postRepeatable). Any other request fails with SdkError.OutcomeUnknown
instead, because the platform may have applied it. A 500 is never retried. The API is
blocking; scale with virtual threads.
import { FlowCatalystClient } from "@flowcatalyst/sdk";
const client = new FlowCatalystClient({ baseUrl: process.env.FLOWCATALYST_BASE_URL!, clientId: process.env.FLOWCATALYST_CLIENT_ID!, clientSecret: process.env.FLOWCATALYST_CLIENT_SECRET!,});
const result = await client.eventTypes().list();result.match( (page) => console.log(page.items), (error) => console.error(error.type, error.message), // errors are values, not exceptions);Every call returns a neverthrow ResultAsync. Error types: missing_credentials,
invalid_credentials, token_expired, token_fetch_failed, network, timeout,
http_error, validation, not_found, forbidden, conflict, rate_limited. Options:
timeout (30 s), retryAttempts (3 retries after the first request), retryDelay (100 ms),
tokenUrl. 408, 429 and a connection that could not be made are retried for every request;
502, 503, 504 and a failure after the request was sent are retried only for a repeatable
request (GET, HEAD, OPTIONS, PUT, DELETE, or a call marked repeatable), and any other request
ends with an outcome_unknown error. A 500 is never retried. Routes without a resource method
are reachable through client.request(...) with the generated functions.
use FlowCatalyst\Facades\FlowCatalyst;use FlowCatalyst\Exceptions\FlowCatalystException;
try { $result = FlowCatalyst::eventTypes()->list(); foreach ($result->items as $eventType) { echo $eventType->code; }} catch (FlowCatalystException $e) { report($e);}Configured from FLOWCATALYST_BASE_URL, FLOWCATALYST_CLIENT_ID and
FLOWCATALYST_CLIENT_SECRET. The token is cached in Laravel’s cache
(FLOWCATALYST_TOKEN_CACHE_DRIVER, default file), so every worker shares it. Timeout and
retries: FLOWCATALYST_TIMEOUT (30), FLOWCATALYST_RETRY_ATTEMPTS (3),
FLOWCATALYST_RETRY_DELAY (100 ms); FLOWCATALYST_RETRY_ATTEMPTS is the total number of
attempts. 408, 429 and a connection that could not be made are retried for every request;
502, 503, 504 and a failure after the request was sent are retried only for a repeatable
request (GET, HEAD, OPTIONS, PUT, DELETE, or a call made with $repeatable). Any other request
throws OutcomeUnknownException, because the platform may have applied it. A 500 is never
retried.
use flowcatalyst_sdk::client::{ClientCredentials, FlowCatalystClient};
let base = std::env::var("FLOWCATALYST_BASE_URL")?;let client = FlowCatalystClient::new(&base).with_token_source(ClientCredentials::new( &base, std::env::var("FLOWCATALYST_CLIENT_ID")?, std::env::var("FLOWCATALYST_CLIENT_SECRET")?,));let pools = client.dispatch_pools().list(&Default::default()).await?;The token is cached until 60 seconds before expiry, fetched single-flight, and refetched once
after a 401. Retries use backoff, 3 retries from 100 ms by default (with_retry). 408, 429 and
a failure to connect are retried for every request; 502, 503, 504 and a failure after the
request was sent are retried only for a repeatable request (GET, HEAD, OPTIONS, PUT, DELETE, and
the few POSTs the SDK marks), and any other request fails with ClientError::OutcomeUnknown.
A 500 is never retried.
Errors are ClientError::Api with the platform’s {error, message}.
Create one client per process and share it: each client holds its own token cache.
Ask for less than you hold
Section titled “Ask for less than you hold”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:
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.
Errors
Section titled “Errors”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. |
Acting for a person
Section titled “Acting for a person”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.
Calling as a developer
Section titled “Calling as a developer”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.
Related
Section titled “Related”- HTTP API reference: every route, with its permission.
- Tokens and token claims.
- Principals.
- SDK pages: Go client and auth, Java auth, TypeScript client, PHP control plane, Rust.