/v1/operations/{operationId}/sourceWhen to use
Save a complete handler as a draft. First read getSource, edit that source, and pass its revision, dataFlowRevision, and updatedAt back as the expected values (the JSON values below are illustrative). A 409 conflict means the source or configuration changed; read again and reconcile your edits before retrying.
For agents
Use JavaScript and module.exports = { handler }. Use event.query(sql) for local tables, event.remoteQuery(connectorId, sql) for live SQL sources, and event.currentDate for relative dates. Imports and require() are unavailable. Return flat row objects. Saving does not execute or publish; run and inspect the output afterward.
Example
import { PermuteClient } from '@permute/sdk';
const orgClient = new PermuteClient({
apiKey: process.env.PERMUTE_API_KEY!,
});
const client = orgClient.withWorkspace(process.env.PERMUTE_WORKSPACE_ID!);
const operationId = 'oper_revenue123';
const current = await client.operations.getSource(operationId);
// Edit current.source, then submit the complete updated handler.
const newSource = "async function handler(event) { return await event.query(\"SELECT customer, SUM(revenue) AS revenue FROM blok_revenue GROUP BY customer\"); } module.exports = { handler };";
const result = await client.operations.updateSource(operationId, {
source: newSource,
expectedRevision: current.revision,
expectedDataFlowRevision: current.dataFlowRevision,
expectedUpdatedAt: current.updatedAt,
});Request body
{
"source": "async function handler(event) { return await event.query(\"SELECT customer, SUM(revenue) AS revenue FROM blok_revenue GROUP BY customer\"); } module.exports = { handler };",
"expectedRevision": {
"revisionId": "rvsn_code123",
"sequence": 1
},
"expectedDataFlowRevision": 2,
"expectedUpdatedAt": "2026-09-10T12:00:00.000Z"
}Response
{
"data": {
"operationId": "oper_revenue123",
"source": "async function handler(event) { return await event.query(\"SELECT customer, SUM(revenue) AS revenue FROM blok_revenue GROUP BY customer\"); } module.exports = { handler };",
"revision": {
"revisionId": "rvsn_code456",
"sequence": 2
},
"instructions": "Sum revenue by customer.",
"dataSourceIds": [
"data_abc123"
],
"dependencyOperationIds": [],
"dataFlowRevision": 3,
"updatedAt": "2026-09-10T12:00:00.000Z"
}
}