Using Tags With Workflows


When you dispatch a workflow, your receive an id that can be used later, for example, to send an event to it later. But doing this requires storing this id in your database. A easier way is to use tags.

When dispatching a workflow, you can provide a tag:

  • using Zenaton GraphQL API:
curl --request POST \
  --url 'https://gateway.zenaton.com/graphql' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer <api Token>' \
  --data '
  {
    "query": "mutation($input: DispatchWorkflowInput!) { dispatchWorkflow(input: $input) { id } }",
    "variables": {
      "input": {
        "appId": "<app id>",
        "environment": "<environment>",
        "name": "<workflow name>",
        "input": "[...<workflow input>]",
        "tag": "<tag>"
      }
    }
  }'
  • using Zenaton Node.js SDK:
zenaton.run.withTag("<tag>").workflow("<workflow name>", ...<workflow input>);
  • from a workflow:
this.run.withTag("<tag>").workflow("<workflow name>", ...<workflow input>);

WARNING

This limitation will be removed in the near future, but currently, only one tag is possible.

It is recommended to use a tag such as "id:fda33f3c-323a-4c0d-88f3-1d8f4b812771" or "email:gilles@gmail.com".

Then a specific workflow can be referenced using the workflow name and tag, for example to send an event to it:

  • using Zenaton GraphQL API:
curl --request POST \
  --url 'https://gateway.zenaton.com/graphql' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer <api Token>' \
  --data '
  {
    "query": "mutation($input: SendEventToWorkflowsInput!) { sendEventToWorkflows(input: $input) { status } }",
    "variables": {
      "input": {
        "appId": "<app id>",
        "environment": "<environment>",
        "selector": { "name": "<workflow name>", "tag": "<tag>" },
        "name": "<event name>",
        "data": "[...<event data>]"
      }
    }
  }'
  • using Zenaton Node.js SDK:
zenaton.select.workflow("<name>").withTag("<tag>").send("<event name>", ...<event data>);
  • from a workflow:
this.select.workflow("<name>").withTag("<tag>").send("<event name>", ...<event data>);

WARNING

Currently, a tag can be used only for a selection by tag and workflow name. This limitation will be removed in the near future.