Skip to main content
A Code step runs your own JavaScript in a flow. Use one for logic the ion-api actions don’t cover. The sample on this page reads the purchase order that fired the flow. It needs a flow that triggers on Purchase Orders - Create and a saved test payload. See Create a flow and Test a flow.
Before you ask an AI coding agent to write or change Code step code, point it at llms.txt, an index of this manual for AI agents, or llms-full.txt for the full text, and at the API reference. The agent then uses real queries, mutations, and field names.

Add a Code step

  1. In Workflow Builder, click + under the trigger, search for Code, and select Code Block.
  2. In the step’s Configure tab, open the code editor, replace its contents with the sample code, and click the check mark to close the editor.
  3. Click Save > Save draft.
  4. Run the flow with your saved payload, as described in Run the flow with a saved payload.
  5. In Run history, click Code Block. Check the purchase order on its Output tab, and the lines the code logged on its Logs tab.

How the code reads your ION connection

When a Code step runs, it receives the flow’s config variables as configVars. Your ION connection is one of them. Its fields hold the Client ID as clientId and the Client Secret as clientSecret. The sample finds the connection that has a clientId, and exchanges the two for an access token, so you never paste credentials into the code. The code reads the trigger’s output from stepResults. The purchase order’s ID is at results.body.data.data.id.

Sample code

This sample gets an access token, then queries the purchase order the trigger fired for:
The sample’s URLs point to the US sandbox, so the ION connection must use sandbox API keys. For another region or environment, replace tokenUrl and apiUrl with that environment’s auth server and API endpoint from ION environments.