Examples
Code snippets and patterns for FluidGrids development. The TypeScript examples use @fluidgrids/sdk and assume a signed-in client:
import { FluidGridsSDK } from '@fluidgrids/sdk';
const sdk = new FluidGridsSDK({
accessToken: process.env.FG_ACCESS_TOKEN,
refreshToken: process.env.FG_REFRESH_TOKEN,
});
await sdk.auth.issueWorkspaceToken(process.env.FG_WORKSPACE_ID ?? '', process.env.FG_ORGANIZATION_ID ?? '');
Trigger a workflow and wait for it
const run = await sdk.fluidgrids.workflows.trigger({
workflowKey: 'order-to-cash',
version: '3',
triggerNodeId: 'trigger-1',
triggerData: { orderId: 'ORD-12345' },
idempotencyKey: 'ORD-12345',
});
console.log('Run started:', run.runId);
const completed = await sdk.fluidgrids.runs.waitForCompletion(run.runId, {
pollInterval: 2000,
timeout: 120_000,
});
console.log('Run finished:', completed.status);
List recent failed runs
const failed = await sdk.fluidgrids.runs.list({ status: 'FAILED', limit: 20 });
for (const run of failed.items) {
console.log(`${run.id}: ${run.workflowKey} v${run.version} — ${run.errorMessage ?? 'no message'}`);
}
Retry the failed node of each failed run
const failedRuns = await sdk.fluidgrids.runs.list({ status: 'FAILED', limit: 50 });
for (const summary of failedRuns.items) {
const run = await sdk.fluidgrids.runs.get(summary.id);
const failedNode = run?.nodeStates?.find((state) => state.status === 'FAILED');
if (!failedNode) continue;
await sdk.fluidgrids.runs.retryNode(summary.id, failedNode.nodeId);
console.log(`Retried ${failedNode.nodeId} in ${summary.id}`);
}
Retrying a node needs Editor on node-state, which the Automation Owner, Automation Lead, Workflow Designer and Run Operator roles have.
Create a credential
A credential is created in two steps: the connection first, with no secret material, then its secret.
const types = await sdk.fluidgrids.credentials.listTypes({ search: 'stripe' });
const stripe = types.items[0];
if (!stripe) throw new Error('Stripe is not available in this workspace');
const credential = await sdk.fluidgrids.credentials.create({
name: 'Stripe production',
providerId: stripe.id,
});
await sdk.fluidgrids.credentials.authenticateWithApiKey(credential.id, process.env.STRIPE_KEY ?? '');
const test = await sdk.fluidgrids.credentials.test(credential.id);
console.log(test);
From the CLI
fluidgrids workflows trigger order-to-cash --wf-version 3 --trigger-node trigger-1 \
--input '{"orderId":"ORD-12345"}' --format json
fluidgrids runs list --status FAILED --format table
fluidgrids runs logs <runId> --level ERROR
To run a workflow on a schedule, give it a Schedule Trigger in the builder (for example the cron expression 0 9 * * *) and activate it; fluidgrids scheduled-jobs list then shows the schedule.
Call a webhook trigger with a signature
BODY='{"orderId":"ORD-12345"}'
TS=$(date +%s)
SIG=$(printf '%s.%s' "$TS" "$BODY" | openssl dgst -sha256 -hmac "$FG_WEBHOOK_SECRET" -hex | sed 's/^.* //')
curl -X POST "$FG_WEBHOOK_URL" \
-H 'Content-Type: application/json' \
-H "X-Webhook-Timestamp: $TS" \
-H "X-Webhook-Signature: sha256=$SIG" \
-d "$BODY"
See Webhooks for the other authentication methods and the response modes.
Selecting an environment
All examples default to production. For alpha, set FLUIDGRIDS_WORKSPACE_ENDPOINT and FLUIDGRIDS_GLOBAL_ENDPOINT to the alpha gateways (and FLUIDGRIDS_OIDC_ISSUER for CLI sign-in), or pass workspaceEndpoint and globalEndpoint to the SDK constructor. See Node SDK › Configuration.