/journey/start request returns an instanceId straight away, and you poll /journey/state/fetch for the result.
With synchronous execution, the start request waits for the journey to finish and returns the result in the same response. If the journey doesn’t finish within the wait time, then you get the instanceId and poll for the result as usual.
When to use synchronous execution
Use synchronous execution for server-to-server API journeys that meet both of these conditions:- You supply all the data the journey needs upfront in
context.subject. - The journey usually finishes within a few seconds. For example, a journey that screens against PEPs and sanctions lists or runs a data verification check.
- Hosted journeys, where
deliveryis"page". The API rejects the request. - Journeys that collect data from the end user, such as document images or a selfie.
- Long-running journeys that often take longer than the wait time.
Before you begin
Make sure you have:- Published API journey: All the domain elements that the journey needs must be in the start interaction, so that you can prefill them. To move domain elements to the start interaction, see Start a journey in partial prefill mode.
- Access token: Obtained in Step 1: Authenticate.
Start a journey synchronously
To wait for the result, setinlineResult to true in context.config. To limit how long the request waits, set syncWaitSeconds.
cURL
Request body fields
These fields control synchronous execution. For the other start request fields, see Step 2: Start a journey.Validation errors
The API rejects the request with a400 error, and doesn’t create a journey, in these cases:
- You set
syncWaitSecondswithout settinginlineResulttotrue. - You set
syncWaitSecondsto zero, a negative number or a value that isn’t an integer. - You set
inlineResulttotrueanddeliveryisn’t"api".
Handle the response
The API returns201 Created for every synchronous outcome. Check the top-level status field to decide what to do next.
The
state object has the same structure as the /journey/state/fetch response. You can parse the result of both modes with the same code.
The top-level
status describes the start call, and state.status describes the journey. They usually match, but when a journey fails, the top-level status is failed and state.status is Error. Base your logic on the top-level status, and read the details from state.Example completed response
JSON
state, see Step 5: Fetch journey state.
Handle each outcome in code
The following example starts a journey synchronously and handles eachstatus. The pollUntilComplete function is the polling example from Step 5: Fetch journey state. You write handleInteraction to collect and submit the extra data.
Best practices
- When the response
statusispendingorstarted, poll with the returnedinstanceId. Don’t send the start request again, because that starts a second journey. - If your journey sends a completion webhook, then the webhook still fires in synchronous mode. It might arrive before the start response does. Process webhook events idempotently, so that you handle each result once.
- Keep
syncWaitSecondsbelow the timeout of every component between your server and GBG Go, such as proxies and load balancers.
FAQ
What is the difference between sync and async journey execution?
What is the difference between sync and async journey execution?
In the v2 API, journey execution is asynchronous by default.When you start a journey, the API returns an
instanceId immediately. Backend modules such as document verification, face matching, data checks process in the background.To track progress, you poll the /journey/interaction/fetch endpoint to discover when the next interaction is available, or poll /journey/state/fetch to check the overall journey status.The recommended polling approach is to call the fetch endpoint at a base interval of 10 seconds, apply backoff on errors, and stop when the journey status changes from InProgress to either Completed or Error.For server-to-server API journeys where you prefill all the data, you can opt in to synchronous execution instead. Set inlineResult to true in context.config, and the start request waits for the journey and returns the result. For details, see Run a journey synchronously.If you are migrating from v1: the async: true flag was a v1-specific concept. In v2, async behaviour is the default and does not need to be specified.