For the fields each block takes, see the Workflow block configuration reference.
Before you begin
- Create an API key with the
Edit Workflowspermission. To run Workflows with the API, the key also needs theExecute Workflow Runspermission. - Find the base URL for your workspace. The commands on this page use the US base URL,
https://api.getcortexapp.com. - Check the prerequisites listed with each example. Some examples need an integration to be configured in your workspace.
Creating a Workflow from a definition
The Workflows API accepts a definition as YAML (Content-Type: application/yaml) or JSON (Content-Type: application/json). The keys are the same in both formats. If a Workflow with the same tag already exists, Cortex replaces it with the new definition.
1
Save the definition
Copy an example from this page and save it as a file, such as
workflow.yaml.2
Validate the definition
Send the file to the Validates YAML descriptor endpoint. Cortex checks the definition without saving it, and returns
ok and a list of violations.3
Create the Workflow
Send the same file to the Create or update workflow endpoint.
4
Run the Workflow
Run it from the Cortex UI, or with the Run a workflow endpoint. Each example below includes a run request.
Use
--data-binary rather than -d to send a YAML file. -d removes line breaks, which breaks the YAML.Look up an entity’s owners
This Workflow runs on a service. It calls the Cortex API to get the entity’s details, then uses a Data transformation block to pull out the names of the teams that own it. When the run finishes, Cortex shows the owners in the run response. Prerequisites: An admin with theEdit Settings permission must turn on the Cortex integration for HTTP blocks, under Settings > Workflows > HTTP block. If you’ve limited the integration’s allowed actions, Read must stay on. See Controlling which integrations HTTP blocks can use.
In newer workspaces, every integration starts off for HTTP blocks. If the Cortex integration is off, the run fails with the message “Cortex integration is disabled for HTTP blocks. Integrations can be enabled in settings.”
filter.type: ENTITYmakes this an entity-scoped Workflow, andentityFilterlimits it to services. Because it runs on an entity, the blocks can readcontext.entity.- The HTTP request block uses
integration: Cortex, so Cortex adds the base URL and credentials. Theurlis a relative path that templates in the entity’s tag. - The HTTP request block writes the parsed response to
actions.get-entity.outputs.body. The jq expression reads it with a leading dot, and quotes the slug because it contains a hyphen. runResponseTemplateshows the jq result to the user when the run finishes.
my-service with the tag of a service in your workspace.
Branch on user input
This Workflow asks the user for a service name and a target environment, then takes a different path depending on the environment. Production deployments get a reminder to open a change request, and every other environment takes the fallback path. Prerequisites: None.- The User input block pauses the run until the user submits the form. Each field’s
keybecomes an output, such asactions.choose-environment.outputs.environment. - The Branch block’s
outgoingActionslists the first block of every path, including the fallback path. - The
productionpath’sexpressionis a CEL expression. It reads the user’s answer without a leading dot. - The paths don’t join again, so the Branch block doesn’t set
joiningAction. Each path ends with a block whoseoutgoingActionsis[]. restrictActionCompletionToRunnerUser: truemeans only the person who started the run can fill in the form.
isRunnableViaApi: false and is meant to run from the UI.
Send a Slack notification
This Workflow posts a release announcement to a Slack channel. The release version comes from a Workflow variable, so you can set it when you start the run, which makes this Workflow a good fit for a CI/CD pipeline. Prerequisites: Configure the Slack integration, and make sure Cortex can post to the channel (see the Slack block in Adding blocks to a Workflow). Replacerelease-announcements with the name of your channel, without the #.
variablesdeclaresrelease-versionwith a default value. Blocks read it as{{variables.release-version}}.- When you run the Workflow with the API, set the variable in
initialContext, keyed by its slug. If you leave it out, Cortex uses the default. - The Slack block’s
messageis a template, so it can include values from the run state, such as the name of the user who started the run.
Slack blocks can’t read secrets from
context.secrets.Wait for an external system
This Workflow asks the user for an environment name, sends a request to an external provisioning service, and pauses until that service reports back. It’s useful for work that takes longer than a single HTTP request, such as provisioning infrastructure or running a CI pipeline. Prerequisites: An external service that accepts the request and can call the Cortex API when it’s done. Replacehttps://provisioner.example.com/environments with your service’s URL.
- When the Asynchronous HTTP request block runs, Cortex replaces
{{callbackUrl}}with a URL that’s unique to this run and block, sends the request, and pauses the Workflow. Always use two curly braces for{{callbackUrl}}. - The external service calls the callback URL when it’s done. If it doesn’t call back within
timeoutInSeconds(one hour here), the block fails with the statustimed_out. - The callback’s
responseobject becomesactions.provision.outputs.result.output, so the next block can read the values the external service sent back.
POST request to the callback URL with a Cortex API key that has the Execute Workflow Runs permission:
status to SUCCESS to continue the Workflow, FAILURE to fail the block, or UPDATE to report progress and keep waiting. For the full request format, see Update asynchronous HTTP request Workflow block.
Adapting the examples
- Change the
tagbefore you create a copy. Creating a Workflow with an existing tag replaces that Workflow. - Keep slugs and references in sync. If you rename a block’s
slug, update everyoutgoingActions,outgoingAction, and template that refers to it. - Start in the UI when you’re unsure. Build the Workflow in the Workflow editor, then export it as YAML (see Workflows as code) to get the exact values for your workspace, such as team IDs and integration aliases.
- Reference run data with the syntax each field expects. See Referencing run data in block fields.