> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to trigger a Workflow Builder workflow

This topic demonstrates how to trigger a Workflow Builder [workflow](/docs/workflow-builder-api/workflow-builder101/workflows). This example will update [participant](/docs/workflow-builder-api/workflow-builder101/participants) information for a workflow and create and start a new instance of the workflow.

For a walkthrough of the process to trigger a workflow, see this video:

## Prerequisites

This how-to requires a published workflow in your account. If you are running this how-to from our launcher projects, this workflow will be created for you. The workflow will include three steps:

* Set up invite
* Sign an envelope from a template with a signer and a cc recipient
* Show confirmation screen

> **Note**
>
> Run this code example from our [Quickstart](/docs/esign-rest-api/quickstart) or launcher projects: [Bash](https://github.com/docusign/code-examples-bash), [C#](https://github.com/docusign/code-examples-csharp), [Java](https://github.com/docusign/code-examples-java), [Node.js](https://github.com/docusign/code-examples-node), [PowerShell](https://github.com/docusign/code-examples-powershell).

## Required data

Running the code in this how-to requires this data:

| Data element          | Description                                                                                                                                                                                                                                                                              |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \{API_ACCOUNT_ID}     | A [GUID](http://guid.one/) value that identifies your account. This value is automatically generated by Docusign for any account you create. Copy the value from the **API Account ID** field on the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=appsAndKeys) page. |
| \{BASE_PATH}          | A string value that forms the root of the URL required to make API calls. The base path value in the example code is set to target the developer environment at https\://\<domain> Where \<domain> is  for the developer environment and  for production.                                |
| \{INSTANCE_NAME}      | A string value for the name of the Workflow Builder workflow instance.                                                                                                                                                                                                                   |
| \{CC_RECIPIENT_EMAIL} | A string value for the email address of the carbon copy recipient.                                                                                                                                                                                                                       |
| \{CC_RECIPIENT_NAME}  | A string value for the name of the carbon copy recipient.                                                                                                                                                                                                                                |
| \{SIGNER_EMAIL}       | A string value for the email address where the signer will receive a notification of the signing request.                                                                                                                                                                                |
| \{SIGNER_NAME}        | A string value for the full name of the signer.                                                                                                                                                                                                                                          |
| \{WORKFLOW_ID}        | A GUID value that identifies your Workflow Builder workflow.                                                                                                                                                                                                                             |

## Step 1. Obtain your OAuth token

To make the API calls shown in this how-to, you need a valid OAuth access token. Docusign supports access tokens for three different recommended OAuth grant types: Public Authorization Code Grant, Confidential Authorization Code Grant, and JSON Web Token (JWT) Grant. Choose the OAuth grant type appropriate for your scenario.

See [Confidential Authorization Code Grant](/platform/auth/authcode#confidential-authorization-code-grant) for guidance on your options to get an Confidential Authorization Code Grant  OAuth token.

Workflow Builder OAuth access tokens are the same ones used for our [eSignature REST API](/docs/esign-rest-api/esign101/auth), although you must request the `signature` scope and one or more Workflow Builder scopes to call the Workflow Builder API. The endpoint calls made in this how-to require that you request the Workflow Builder-specific `aow_manage` scope when obtaining your access token.

> **Note**
>
> See [Workflow Builder Authentication](/docs/workflow-builder-api/auth) for details and the full list of Workflow Builder scopes.

![Three icons that represent the three methods a user can use to obtain an OAuth token: JSON Web Token (JWT), Public Authorization Code Grant (ACG), and Confidential Authorization Code grant](/_fern-files/_img/64f473773042ee439449a096bf7673292b1585b86a4ccc55f82ba0dda41f61a1.webp)

## Step 2. Construct your API headers

After you have a valid OAuth access token, you are ready to construct the API headers that you will pass to the API call. Construct your headers like this, but make sure to substitute your valid OAuth access token for \{ACCESS_TOKEN}.

**`Bash`**

```bash title="Bash"
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
    '--header' "Accept: application/json" \
    '--header' "Content-Type: application/json")
```

**`C#`**

```csharp title="C#"
private static IamClient CreateAuthenticatedClient(string basePath, string accessToken)
{
    return IamClient.Builder()
        .WithServerUrl(basePath)
        .WithAccessToken(accessToken)
        .Build();
}
```

**`Java`**

```java title="Java"
protected IamClient createAuthenticatedClient(String accessToken) {
    return IamClient.builder()
            .accessToken(accessToken)
            .build();
}
```

**`Node.js`**

```javascript title="Node.js"
const client = new iam.IamClient({ accessToken: args.accessToken });
```

**`PowerShell`**

```text title="PowerShell"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.add("Authorization", "Bearer $accessToken")
$headers.add("Content-Type", "application/json")
$headers.add("Accept", "application/json")
```

## Step 3. Retrieve the triggerURL

Make a `Workflows:getWorkflowTriggerRequirements` request to retrieve the desired workflow definition and extract the `url` property from the response.

Here’s how you make the call, but make sure to substitute your API account ID for \{API_ACCOUNT_ID}, and the desired workflow ID for \{WORKFLOW_ID}.

**`Bash`**

```bash title="Bash"
response=$(mktemp /tmp/response-wftmp.XXXXXX)
Status=$(
    curl -w '%{http_code}' --request GET "${base_path}/accounts/${account_id}/workflows" \
    "${Headers[@]}" \
    --output ${response}
)
# If the status code returned is greater than 201 (OK / Accepted), display an error message with the API response.
if [[ "$Status" -gt "201" ]]; then
    echo ""
    echo "Unable to retrieve a workflow definition"
    echo ""
    cat $response
    exit 0
fi

echo "Workflows found:"
cat $response
echo ""

workflow_ids=$(grep -B 3 -E '"status": "active"' "$response" | grep -B 2 '"name": "Example workflow - send invite to signer"' | grep '"id":' | sed -n 's/.*"id": "\([^"]*\)".*/\1/p')

# Read the existing workflow ID from the config file
config_workflow_id=""
if [ -s config/WORKFLOW_ID ]; then
  config_workflow_id=$(cat config/WORKFLOW_ID)
fi

# If there are multiple active workflows, checks if the config_workflow_id is in the workflow list and uses the config_workflow_id.
if [ -n "$config_workflow_id" ] && echo "$workflow_ids" | grep -q "$config_workflow_id"; then
  workflow_id="$config_workflow_id"
else
  workflow_id=$(echo "$workflow_ids" | head -n 1)
fi

# Error handling if no active workflow ID is found
if [ -z "$workflow_id" ]; then
  echo "Error: No active workflow ID found in the response."
  echo "Please create and publish a workflow before running this example."
  exit 0
fi

# Get the trigger URL
# workflow_id comes from the response of the Workflows: getWorkflowsList endpoint
response=$(mktemp /tmp/response-wftmp.XXXXXX)
Status=$(curl -s -w "%{http_code}\n" -i --request GET "${base_path}/accounts/${account_id}/workflows/${workflow_id}/trigger-requirements" \
    "${Headers[@]}" \
    --output ${response})
# If the status code returned is greater than 201 (OK / Accepted), display an error message with the API response.
if [[ "$Status" -gt "201" ]]; then
    echo ""
    echo "Unable to trigger a new instance of the specified workflow ${workflow_id}"
    echo ""
    cat $response
    exit 0
fi

cat $response
echo ""

trigger_url=$(grep '"url":' $response | sed -n 's/.*"url": "\([^"]*\)".*/\1/p')
decoded_trigger_url=$(echo $trigger_url | sed 's/\\u0026/\&/g')
```

**`C#`**

```csharp title="C#"
{
    var client = CreateAuthenticatedClient(basePath, accessToken);
    return await client.WorkflowBuilder.Workflows.GetWorkflowsListAsync(accountId, Status.Active);
}
```

**`Java`**

```java title="Java"
public static GetWorkflowsListResponse getMaestroWorkflow(
        IamClient client,
        String accountId) throws Exception {
    return client.workflowBuilder()
            .workflows()
            .getWorkflowsList(accountId, Optional.of(Status.ACTIVE), Optional.empty());
}
```

**`Node.js`**

```javascript title="Node.js"
return await client.maestro.workflows.getWorkflowsList({ accountId: args.accountId, status: 'active' });
```

**`PowerShell`**

```text title="PowerShell"
Invoke-RestMethod `
  -Uri "${base_path}/accounts/${accountId}/workflows/${workflowId}/trigger-requirements" `
  -Method 'GET' `
  -Headers $headers `
  -OutFile $response

$jsonContent = Get-Content -Path $response -Raw | ConvertFrom-Json
$triggerUrl = $jsonContent.trigger_http_config.url
$triggerUrl = $triggerUrl -replace "\\u0026", "&"
```

## Step 4. Construct the request body

Construct the `trigger_inputs_object` to include values for the [variables](/docs/workflow-builder-api/workflow-builder101/variables) defined in the workflow.

**`Bash`**

```bash title="Bash"
request_data=$(mktemp /tmp/request-wf-001.XXXXXX)
printf \
'{
  "instance_name": "'"$instance_name"'",
  "trigger_inputs": {
    "signerEmail": "'"${signer_email}"'",
    "signerName": "'"${signer_name}"'",
    "ccEmail": "'"${cc_email}"'",
    "ccName": "'"${cc_name}"'"
  }
}' >$request_data
```

**`C#`**

```csharp title="C#"
var triggerInputs = new Dictionary<string, TriggerInputs>
{
    { "signerName", CreateTriggerInput(signerName) },
    { "signerEmail", CreateTriggerInput(signerEmail) },
    { "ccName", CreateTriggerInput(ccName) },
    { "ccEmail", CreateTriggerInput(ccEmail) },
};
```

**`Java`**

```java title="Java"
Map<String, TriggerInputs> triggerInputs = new HashMap<>();
triggerInputs.put("signerName", createTriggerInput(signerName));
triggerInputs.put("signerEmail", createTriggerInput(signerEmail));
triggerInputs.put("ccName", createTriggerInput(ccName));
triggerInputs.put("ccEmail", createTriggerInput(ccEmail));
```

**`Node.js`**

```javascript title="Node.js"
const triggerInputs = {
  signerName: args.signerName,
  signerEmail: args.signerEmail,
  ccName: args.ccName,
  ccEmail: args.ccEmail,
};
```

**`PowerShell`**

```text title="PowerShell"
$body = @"
{
  "instance_name": "$instance_name",
  "trigger_inputs": {
    "signerEmail": "$signerEmail",
    "signerName": "$signerName",
    "ccEmail": "$ccEmail",
    "ccName": "$ccName"
  }
}
"@
```

## Step 5. Call the Workflow Builder API

Now that you have constructed your API headers and request body, make a POST request using the `url` property obtained in Step 3 to trigger a new instance of the workflow. The `url` property will also include two query parameters: `mtid` and `mtsec`. These values are generated by the Workflow Builder service when the workflow is published and are used to authenticate the request and identify a valid workflow.

> **Note**
>
> View the source code for this how-to on GitHub: [Bash](https://github.com/docusign/code-examples-bash/blob/master/examples/Maestro/eg001TriggerWorkflow.sh/), [C#](https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/Maestro/Examples/TriggerMaestroWorkflow.cs), [Java](https://github.com/docusign/code-examples-java/blob/master/src/main/java/com/docusign/controller/maestro/examples/Mae001TriggerWorkflowController.java), [Node.js](https://github.com/docusign/code-examples-node/blob/master/lib/maestro/examples/triggerWorkflow.js),  or [PowerShell](https://github.com/docusign/code-examples-powershell/blob/master/examples/Maestro/eg001TriggerWorkflow.ps1).

**`Bash`**

```bash title="Bash"
response=$(mktemp /tmp/response-wftmp.XXXXXX)
# The ${decoded_trigger_url} variable is extracted from the response from a previous API call
# to the Workflows: getWorkflowTriggerRequirements endpoint.
Status=$(curl -s -w "%{http_code}\n" -i --request POST ${decoded_trigger_url} \
    "${Headers[@]}" \
    --data-binary @${request_data} \
    --output ${response})
```

**`C#`**

```csharp title="C#"
var triggerWorkflow = new TriggerWorkflow
{
    InstanceName = instanceName,
    TriggerInputs = triggerInputs,
};

return await client.WorkflowBuilder.Workflows.TriggerWorkflowAsync(
    triggerWorkflow,
    accountId,
    workflowId);
```

**`Java`**

```java title="Java"
var triggerWorkflow = new TriggerWorkflow(instanceName, triggerInputs);

return client.workflowBuilder()
        .workflows()
        .triggerWorkflow(accountId, workflowId, triggerWorkflow);
    }
```

**`Node.js`**

```javascript title="Node.js"
const triggerWorkflow = { instanceName, triggerInputs };

const result = await client.maestro.workflows.triggerWorkflow({
  accountId: args.accountId,
  workflowId: workflowId,
  triggerWorkflow,
});

return result;
```

**`PowerShell`**

```text title="PowerShell"
$triggerResult = Invoke-WebRequest -uri $triggerUrl -headers $headers -body $body -method POST -UseBasicParsing
```

## Expected response

If you run this code example from our Quickstart or launcher projects, you should see a JSON response similar to the code shown. You will also receive an email at the address supplied in Step 4 to complete the workflow.

**`Sample response`**

```json title="Sample response"
{
    "instanceId": "5be2a8ad-xxxx-xxxx-xxxx-f4e928383eb3",
    "workflowInstanceUrl": "https://demo.services.docusign.net/aow-auth/v1.0/accounts/1caf2cc9-xxxx-xxxx-xxxx-14d63c1ced6b/workflows/execution?mtid=cb6a48f3-xxxx-xxxx-xxxx-f2bf10fafc39&mtsec=tnrwWLmJH8-xxxxxxxx-Kpy5nGkeQdjU4G7yj9I6yQM"
}
```

## Step 6. (Optional) Embed the instance in an iframe

To present the workflow to your users, embed the `instanceUrl` in an iframe in your application. This can be done in any front-end environment that supports HTML. This iframe provides a complete browser-based workflow experience for your end users.

**`Bash`**

```bash title="Bash"
-->
<div>
    <iframe src=$instanceUrl width=800 height=600>
    </iframe>
</div>
<!--
```

**`C#`**

```csharp title="C#"
-->
<iframe width="900" height="600" src="@ViewBag.Url">
</iframe>
<!--
```

**`Java`**

```java title="Java"
-->
<iframe width="900" height="600" src="${url}">
</iframe>
<!--
```

**`Node.js`**

```javascript title="Node.js"
-->
<iframe width="900" height="600" src=<%- instanceUrl %>></iframe>
<!--
```

**`PowerShell`**

```text title="PowerShell"
-->
    <div>
        <iframe src='$instanceUrl' width='800' height='600'></iframe>
    </div>
<!--
```

## Expected response

If the workflow was triggered and embedded correctly, your application should display the Workflow Builder workflow in an iframe. The embedded experience will load the first step of the workflow and allow the user to begin interacting with it directly in the browser.

![A screenshot showing an embedded agreement workflow](/_fern-files/_img/05b22218e68bd6275cca268174625d0cdb2b1520a8bbb222df6aa67f0817dc19.webp)

## Next steps

* Run this code example from our [Quickstart](/docs/esign-rest-api/quickstart) or launcher projects: [Bash](https://github.com/docusign/code-examples-bash), [C#](https://github.com/docusign/code-examples-csharp), [Java](https://github.com/docusign/code-examples-java), [Node.js](https://github.com/docusign/code-examples-node), [PowerShell](https://github.com/docusign/code-examples-powershell).
* Learn more about [Workflows](/docs/workflow-builder-api/workflow-builder101/workflows).
* See how to [Go-Live](/docs/workflow-builder-api/publishing-go-live) with a completed app and find the base path for API calls in the production environment.
* [Workflow start methods](https://support.docusign.com/s/document-item?language=en_US\&bundleId=yff1696971835267\&topicId=ztb1727892686033.html).