How to simulate an automation and retrieve the simulation result using GraphQL
Overview
This guide explains how to simulate an automation execution using Pipefy's GraphQL API. The process involves two steps:
- Create a simulation using the
createAutomationSimulation
mutation. - Retrieve the simulation result using the
automationSimulation
query.
This flow allows you to test automation logic and preview results before applying changes.
Prerequisites
- Authentication: Use a Service Account token.
- Permissions: Ensure your token has permission to simulate automations.
- Automation Input: Prepare the input data required for the simulation (such as event and action parameters).
Step 1: Create an Automation Simulation
Use the createAutomationSimulation
mutation to start a simulation. You must provide the required input for the automation.
mutation CreateAutomationSimulation($input: CreateAutomationSimulationInput!) {
createAutomationSimulation(input: $input) {
simulationId
}
}
Variables example:
{
"input": {
"action_id": "generate_with_ai",
"action_repo_id": "2",
"action_params": {
"aiParams": {
"fieldIds": ["123", "321"],
"value": "Read field ${123} and translate it"
}
},
"sampleCardId": "203"
}
}
Key Fields Returned
simulationId
: The unique identifier for the simulation. Use this to query the simulation result.
Step 2: Retrieve the Automation Simulation Result
After creating the simulation, use the automationSimulation
query to check the status and retrieve the result.
query AutomationSimulation($simulationId: ID!) {
automationSimulation(simulationId: $simulationId) {
simulationResult
details {
errorType
message
}
status
}
}
Variables example:
{
"simulationId": "the-id-returned-by-mutation"
}
Key Fields Returned
simulationResult
: The result of the simulation (may be a JSON object with simulated output).details
: Additional details, such as error type and message if applicable.status
: The current status (processing
,success
,failed
).
Example Flow
- Run the mutation to create a simulation and note the returned
simulationId
. - Poll the query with the
simulationId
untilstatus
issuccess
orfailed
. - Review the
simulationResult
anddetails
fields for the outcome.
Example Response (Mutation)
{
"data": {
"createAutomationSimulation": {
"simulationId": "simulation-uuid-123"
}
}
}
Example Response (Query)
{
"data": {
"automationSimulation": {
"simulationResult": {
"fieldId": "simulated value"
},
"details": {
"errorType": null,
"message": "Simulation completed successfully."
},
"status": "success"
}
}
}
Notes
- The simulation process may take some time. Poll the query until the status is
success
orfailed
. - If the simulation fails, check the
details
orerrorMessage
fields for more information. - Use simulation to validate automation logic before deploying