Examples
Code snippets and patterns for FluidGrids development.
Trigger a workflow from a Node.js script
import { createClient } from "@fluidgrids/sdk";
const client = createClient({
baseUrl: "https://graphqlworkspaces.burdenoff.com/workspaces/graphql",
apiKey: process.env.FLUIDGRIDS_API_KEY,
});
async function main() {
const result = await client.workflows.triggerByKey(
"order-to-cash",
undefined,
{
inputData: { orderId: "ORD-12345" },
},
);
console.log("Run started:", result.runId);
const completed = await client.runs.waitForCompletion(result.runId, {
pollInterval: 2000,
timeout: 120000,
});
console.log("Run completed:", completed.status);
}
main();
Trigger a workflow from Python
import asyncio
from fluidgrids_sdk import FluidGridsSDK, FluidGridsConfig, TriggerWorkflowInput
async def main():
config = FluidGridsConfig(
endpoint="https://graphqlworkspaces.burdenoff.com/workspaces/graphql",
api_key="your-api-key",
)
async with FluidGridsSDK(config) as sdk:
result = await sdk.workflows.trigger_by_key(
key="order-to-cash",
input_data=TriggerWorkflowInput(input_data={"orderId": "ORD-12345"}),
)
print(f"Run started: {result.run_id}")
asyncio.run(main())
Schedule a workflow via CLI
# The CLI targets production by default; override with FLUIDGRIDS_API_URL if needed
# export FLUIDGRIDS_API_URL=https://alphagraphqlworkspaces.burdenoff.com/workspaces/graphql
# Trigger manually
fluidgrids workflows trigger WORKFLOW_ID
# Or configure a scheduled trigger in the app with cron: 0 9 * * *
List recent failed runs
const runs = await client.runs.list({
status: "failed",
limit: 20,
});
for (const run of runs.items) {
console.log(`${run.id}: ${run.workflowKey} — ${run.error}`);
}
Retry all failed runs
const runs = await client.runs.list({
status: "failed",
limit: 50,
});
for (const run of runs.items) {
await client.runs.retry(run.id);
console.log(`Retried ${run.id}`);
}
Create a credential
const credential = await client.credentials.create({
name: "Stripe Production Key",
type: "api_key",
data: { apiKey: process.env.STRIPE_KEY },
});
Selecting an environment
All examples default to production. To target another endpoint, configure the tool you are using:
| Tool | How to select the endpoint |
|---|---|
| CLI | FLUIDGRIDS_API_URL, the -u/--url flag, or fluidgrids config set url |
| Node SDK | baseUrl in createClient, or FLUIDGRIDS_ENDPOINT |
| Python SDK | endpoint= in FluidGridsConfig, or FLUIDGRIDS_ENDPOINT |
The BURDENOFF_ENV switch applies only to the browser and VS Code extensions.