Integrating STATEWIZE

How to use STATEWIZE with your existing systems?

TL;DR

  • We have a Javascript SDK and a CLI.

  • You can invoke any flow, using its unique token from the "Integrate" page (access it via the floating menu on the left, in the flow page)

  • You can keep your code on your own repository (i.e GitHub), and use your own CI/CD pipeline in order to deploy serverless functions onto an existing flow, and deploy the updated flow into a certain environment.

Once you've built your flows, you would want to execute (invoke) them at some point.

Most likely, you would want to do that from your own servers, or, in some scenarios, from your website or mobile application (though frontend integration is not recommended due to security concerns).

In order to thrive for maximum security and data isolation, each flow you have has its own set of tokens, which should be used to execute it in a certain environment.

1 token per each flow in a certain environment.

Meaning, each flow, by default, has 4 tokens, one for each of the following environments: [Development, Testing, Staging, Production]

Fetching the right API token

In your flow view, there is a floating menu on the left. It's the same menu you use for adding states and condition to your flow's canvas. This menu has a button "Integrate" - click on it:

This button will take you to a dedicated page, specific for this flow, with execution and deployment tokens:

Each of these tokens can only be used to execute this flow (and no other), in the specified environment.

Let's see a practical integration example. Imagine we are a STATEWIZE user, and we would like to integrate STATEWIZE into our backend server. It would be as easy as:

const execution = await sdk.executions.startExecutionSync({
token: process.env.START_KYC_STATE_MACHINE_TOKEN,
entryPayload: {user: {id: 1234, otherParams: 'whatever-you-need'}}
});

We are using an environment variable START_KYC_STATE_MACHINE_TOKEN which would have a different value based on the environment in which our code is running (i.e the production token in a production environment, or a testing token in the QA environment. It's all up to you :) )

That is it. This code snipped would trigger a flow execution in the same environment as your token.

The easiest one would be using one of our official SDKs:

  1. CLI

Regenerating a token

Each of the tokens can be re-generated using the matching "Rotate" button.

Please be aware that re-generating the token will invalidate your previous token, so your existing integrations may stop working until you update your setup with the new token.