Skip to main content
Skip table of contents

Order flows | Order flow set-up

Creating an order flow

The current structure to define an order flow is to create a JSON of how you want each step to be defined.

Each step definition needs to be defined in a certain structure for the order flow to work properly, currently we have 3 types of step definitions: generate production files, consume rest api, send email.

Below are the interfaces for creating a step definition.

TYPESCRIPT
interface IStepDefinition {
  stepDefinitionId: string; // Unique id used to identify each step definition
  type: StepType; // Type used to define the behaviour of the step
  successStatus: string; // What the order "status" should be when this step finishes executing
  options: StepOptions; // Step-specific options that are sometimes required for a step to work
  timeout?: number | null; // Maximum amount of time this step should be able to run
  onSuccess?: string | null; // The stepDefinitionId of the step that should run if this one succeeds
  onError?: string | null; // The stepDefinitionId of the step that should run after this one fails
}

type StepOptions =
  | IConsumeRestApiOptions
  | ISendEmailOptions
  | IGenerateProductionFilesOptions;

enum StepType {
  CONSUME_REST_API = 'consume-rest-api',
  SEND_EMAIL = 'send-email',
  GENERATE_PRODUCTION_FILES = 'generate-production-files'
}

interface IConsumeRestApiOptions {
  uri: string; // URI where the order object should be POSTed to
}

interface ISendEmailOptions {
  recipients: Array<string>; // Array of email addresses to recieve the email
  subject: string; // Subject of the email
  message: string; // Message body fo the email
}

interface IGenerateProductionFilesOptions {
  fileFormat?: string; // Fileformat of the generated files, currently only obj and stl
}

An order flow is basically a list of IStepDefinitions. Starting with the first step definition in the list, it will continue down the onSuccess path until it reaches the end or an error occurs, where it will then travel down the onError path or complete if no error path is defined.

Below is an example of each supported step definition.

Generate production files

JSON
  {
    "stepDefinitionId": "generate",
    "type": "generate-production-files",
    "successStatus": "In progress",
    "options": {
      "fileFormat": "stl"
    }
  }

Consume rest api

JSON
{
    "stepDefinitionId": "consume",
    "type": "consume-rest-api",
    "successStatus": "In progress",
    "options": {
      "uri": "https://httpbin.org/anything"
    }
  }

Send email

JSON
  {
    "stepDefinitionId": "email",
    "type": "send-email",
    "successStatus": "Success",
    "options": {
      "recipients": ["neil.benin@twikit.com"],
      "subject": "Success subject",
      "message": "Success message"
    }
  }

Order flow example

Below is an example of a working order flow:

  1. It will first generate production files

    • If this fails, it will continue to the step with the stepDefinitionId defined in the onError field, error

    • If this succeeds, it will continue to the step with the stepDefinitionId defined in the onSuccess field, consume

  2. It will now POST the order object to the uri defined in the uri field

    • If this fails, it will continue to the step with the stepDefinitionId defined in the onError field, error

    • If this succeeds, it will continue to the step with the stepDefinitionId defined in the onSuccess field, email

  3. It will now send an email to all of the recipients defined in the recipients field, with a subject as defined in the subject field and a message as defined in the message field

    • If this fails, it will continue to the step with the stepDefinitionId defined in the onError field, error

JSON
[
  {
    "stepDefinitionId": "generate",
    "type": "generate-production-files",
    "successStatus": "In progress",
    "options": {
      "fileFormat": "stl"
    },
    "onSuccess": "consume",
    "onError": "error"
  },
  {
    "stepDefinitionId": "consume",
    "type": "consume-rest-api",
    "successStatus": "In progress",
    "options": {
      "uri": "https://httpbin.org/anything"
    },
    "onSuccess": "email",
    "onError": "error"
  },
  {
    "stepDefinitionId": "email",
    "type": "send-email",
    "successStatus": "Success",
    "options": {
      "recipients": ["neil.benin@twikit.com"],
      "subject": "Success subject",
      "message": "Success message"
    },
    "onError": "error"
  },
  {
    "stepDefinitionId": "error",
    "type": "send-email",
    "successStatus": "Failed",
    "options": {
      "recipients": ["neil.benin@twikit.com"],
      "subject": "Error subject",
      "message": "Error message"
    }
  }
]
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.