> 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 use conditional recipients

> Demonstrates how to create an envelope where the workflow is routed to different recipients based on the value of a transaction.

eSignature REST API 2.1 only

This topic demonstrates how to create an envelope whose workflow [routes](https://support.docusign.com/s/document-item?language=en_US\&rsc_301\&bundleId=gav1643676262430\&topicId=aqm1578456487908.html&_LANG=enus) it to different recipients based on the value of a transaction.

> **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), [PHP](https://github.com/docusign/code-examples-php), [PowerShell](https://github.com/docusign/code-examples-powershell), [Python](https://github.com/docusign/code-examples-python), or [Ruby](https://github.com/docusign/code-examples-ruby).

## 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>/restapi Where \<domain> is demo.docusign.net for the developer environment and is the result of the GetUserInfo call in production. |
| \{SIGNER1_EMAIL}             | A string value for the email address of the first recipient.                                                                                                                                                                                                                                                           |
| \{SIGNER1_NAME}              | A string value for the name of the first recipient.                                                                                                                                                                                                                                                                    |
| \{SIGNER_NOT_CHECKED_EMAIL}  | A string value for the email address of the first conditional recipient.                                                                                                                                                                                                                                               |
| \{SIGNER_NOT_CHECKED_NAME}   | A string value for the name of the first conditional recipient.                                                                                                                                                                                                                                                        |
| \{SIGNER_WHEN_CHECKED_EMAIL} | A string value for the email address of the second conditional recipient.                                                                                                                                                                                                                                              |
| \{SIGNER_WHEN_CHECKED_NAME}  | A string value for the name of the second conditional recipient.                                                                                                                                                                                                                                                       |

## Step 1. Obtain your OAuth token

To make the API call 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.

> **Note**
>
> 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.

![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#"
var docuSignClient = new DocuSignClient(basePath);
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(docuSignClient);
```

**`Java`**

```java title="Java"
ApiClient apiClient = new ApiClient(basePath);
apiClient.addDefaultHeader(HttpHeaders.AUTHORIZATION, BEARER_AUTHENTICATION + userAccessToken);
```

**`Node.js`**

```javascript title="Node.js"
let dsApiClient = new docusign.ApiClient();
dsApiClient.setBasePath(args.basePath);
dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken);
```

**`PHP`**

```php title="PHP"
$config = new Configuration();
$config->setHost($args['base_path']);
$config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
$this->apiClient = new ApiClient($config);
```

**`PowerShell`**

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

**`Python`**

```python title="Python"
api_client = create_api_client(
    base_path=args["base_path"], access_token=args["access_token"]
)
```

**`Ruby`**

```ruby title="Ruby"
configuration = DocuSign_eSign::Configuration.new
configuration.host = args[:basePath]
api_client = DocuSign_eSign::ApiClient.new configuration
api_client.set_default_header('Authorization', "Bearer #{args[:accessToken]}")
```

## Step 3. Construct the request body

Next, create the request body. To create an envelope using the eSignature REST API, construct an envelope body in JSON format. Replace `{SIGNER1_EMAIL}`, `{SIGNER1_NAME}`, `{SIGNER_NOT_CHECKED_EMAIL}`, `{SIGNER_NOT_CHECKED_NAME}`, `{SIGNER_WHEN_CHECKED_EMAIL}` and `{SIGNER_WHEN_CHECKED_NAME}` with your recipients’ data in the JSON request body.

The `workflow` section contains the information necessary to determine the action; in this case, `pause_before`, and the trigger `routing_order`, will cause the workflow to pause before the envelope is sent to the second recipient, whose information is in `conditionalRecipients`.

**`Bash`**

```bash title="Bash"
printf \
  '{
  "documents":
  [
    {
      "documentBase64": "VGhhbmtzIGZvciByZXZpZXdpbmcgdGhpcyEKCldlJ2xsIG1vdmUgZm9yd2FyZCBhcyBzb29uIGFzIHdlIGhlYXIgYmFjay4=",
      "documentId": "1",
      "fileExtension": "txt",
      "name": "Welcome"
    }
  ],
  "emailSubject": "ApproveIfChecked",
  "workflow":
  {
  "workflowSteps":
  [
    {
   "action": "pause_before",
    "triggerOnItem": "routing_order",
    "itemId": 2,
    "status": "pending",
    "recipientRouting":
      {
        "rules":
        {
          "conditionalRecipients":
          [
            {
            "recipientId": 2,
            "order": "0",
            "recipientGroup":
              {
                "groupName": "Approver",
                "groupMessage": "Members of this group approve a workflow",
                "recipients":
                [
                  {
                    "recipientLabel": "signer2a",
                    "name": "'"${SIGNER_NOT_CHECKED_NAME}"'",
                    "roleName": "Signer when not checked",
                    "email": "'"${SIGNER_NOT_CHECKED_EMAIL}"'"
                  },
                  {
                    "recipientLabel": "signer2b",
                    "name": "'"${SIGNER_WHEN_CHECKED_NAME}"'",
                    "roleName": "Signer when checked",
                    "email": "'"${SIGNER_WHEN_CHECKED_EMAIL}"'"
                  }
                ]
              },
              "conditions":
              [
                {
                  "recipientLabel": "signer2a",
                  "order": 1,
                  "filters":
                  [
                    {
                      "scope": "tabs",
                      "recipientId": "1",
                      "tabId": "ApprovalTab",
                      "operator": "equals",
                      "value": "false",
                      "tabType": "checkbox",
                      "tabLabel": "ApproveWhenChecked"
                    }
                  ]
                },
                {
                  "recipientLabel": "signer2b",
                  "order": 2,
                  "filters":
                  [
                    {
                      "scope": "tabs",
                      "recipientId": "1",
                      "tabId": "ApprovalTab",
                      "operator": "equals",
                      "value": "true",
                      "tabType" : "checkbox",
                      "tabLabel": "ApproveWhenChecked"
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    }
    ]
  },
  "recipients":
  {
    "signers":
    [
      {
        "email": "'"${SIGNER1_EMAIL}"'",
        "name": "'"${SIGNER1_NAME}"'",
        "recipientId": "1",
        "routingOrder": "1",
        "roleName": "Purchaser",
        "tabs":
        {
          "signHereTabs":
          [
            {
              "name": "SignHere",
              "documentId": "1",
              "pageNumber": "1",
              "tabLabel": "PurchaserSignature",
              "xPosition": "200",
              "yPosition": "200"
            }
          ]
          ,
          "checkboxTabs":
          [
            {
              "name": "ClickToApprove",
              "selected": "false",
              "documentId": "1",
              "pageNumber": "1",
              "tabLabel": "ApproveWhenChecked",
              "xPosition": "50",
              "yPosition": "50"
            }
          ]
        }
      },
      {
        "email": "placeholder@example.com",
        "name": "Approver",
        "recipientId": "2",
        "routingOrder": "2",
        "roleName" : "Approver",
        "tabs":
        {
          "signHereTabs":
          [
            {
              "name": "SignHere",
              "documentId": "1",
              "pageNumber": "1",
              "recipientId": "2",
              "tabLabel": "ApproverSignature",
              "xPosition": "300",
              "yPosition": "200"
            }
          ]
        }
      }
    ]
  },
"status": "Sent"
}
' >>$request_data
```

**`C#`**

```csharp title="C#"
var envelope = MakeEnvelope(
    recipient1Email,
    recipient1Name,
    conditionalRecipient1Email,
    conditionalRecipient1Name,
    conditionalRecipient2Email,
    conditionalRecipient2Name);
        private static EnvelopeDefinition MakeEnvelope(string recipient1Email, string recipient1Name, string conditionalRecipient1Email, string conditionalRecipient1Name, string conditionalRecipient2Email, string conditionalRecipient2Name)
        {
var document = new Document()
{
    DocumentBase64 = "VGhhbmtzIGZvciByZXZpZXdpbmcgdGhpcyEKCldlJ2xsIG1vdmUgZm9yd2FyZCBhcyBzb29uIGFzIHdlIGhlYXIgYmFjay4=",
    DocumentId = "1",
    FileExtension = "txt",
    Name = "Welcome",
};

var conditionalRecipientRule = new ConditionalRecipientRule()
{
    RecipientId = "2",
    Order = "2",
    RecipientGroup = new RecipientGroup()
    {
        GroupName = "Approver",
        GroupMessage = "Members of this group approve a workflow",
        Recipients = new List<RecipientOption>()
        {
            new RecipientOption(conditionalRecipient1Email, conditionalRecipient1Name, "signer2a", "Signer when not checked"),
            new RecipientOption(conditionalRecipient2Email, conditionalRecipient2Name, "signer2b", "Signer when not checked"),
        },
    },
    Conditions = new List<ConditionalRecipientRuleCondition>
    {
        new ConditionalRecipientRuleCondition
        {
            RecipientLabel = "signer2a",
            Order = "1",
            Filters = new List<ConditionalRecipientRuleFilter>()
            {
                new ConditionalRecipientRuleFilter
                {
                    Scope = "tabs",
                    RecipientId = "1",
                    TabId = "ApprovalTab",
                    Operator = "equals",
                    Value = "false",
                    TabLabel = "ApproveWhenChecked",
                    TabType = "checkbox",
                },
            },
        },
        new ConditionalRecipientRuleCondition
        {
            RecipientLabel = "signer2b",
            Order = "2",
            Filters = new List<ConditionalRecipientRuleFilter>()
            {
                new ConditionalRecipientRuleFilter
                {
                    Scope = "tabs",
                    RecipientId = "1",
                    TabId = "ApprovalTab",
                    Operator = "equals",
                    Value = "true",
                    TabLabel = "ApproveWhenChecked",
                    TabType = "checkbox",
                },
            },
        },
    },
};

var workflowStep = new WorkflowStep()
{
    Action = "pause_before",
    TriggerOnItem = "routing_order",
    ItemId = "2",
    Status = "pending",
    RecipientRouting = new RecipientRouting()
    {
        Rules = new RecipientRules()
        {
            ConditionalRecipients = new List<ConditionalRecipientRule>
            {
                conditionalRecipientRule,
            },
        },
    },
};

var signer1 = new Signer()
{
    Email = recipient1Email,
    Name = recipient1Name,
    RecipientId = "1",
    RoutingOrder = "1",
    RoleName = "Purchaser",
    Tabs = new Tabs
    {
        SignHereTabs = new List<SignHere>()
        {
            new SignHere()
            {
                Name = "SignHere",
                DocumentId = "1",
                PageNumber = "1",
                TabLabel = "PurchaserSignature",
                XPosition = "200",
                YPosition = "200",
            },
        },
        CheckboxTabs = new List<Checkbox>()
        {
            new Checkbox()
            {
                Name = "ClickToApprove",
                Selected = "false",
                DocumentId = "1",
                PageNumber = "1",
                TabLabel = "ApproveWhenChecked",
                XPosition = "50",
                YPosition = "50",
            },
        },
    },
};

var signer2 = new Signer()
{
    Email = "placeholder@example.com",
    Name = "Approver",
    RecipientId = "2",
    RoutingOrder = "2",
    RoleName = "Approver",
    Tabs = new Tabs
    {
        SignHereTabs = new List<SignHere>
        {
            new SignHere()
            {
                Name = "SignHere",
                DocumentId = "1",
                PageNumber = "1",
                RecipientId = "2",
                TabLabel = "ApproverSignature",
                XPosition = "300",
                YPosition = "200",
            },
        },
    },
};

var envelopeDefinition = new EnvelopeDefinition()
{
    Documents = new List<Document> { document, },
    EmailSubject = "ApproveIfChecked",
    Workflow = new Workflow { WorkflowSteps = new List<WorkflowStep> { workflowStep, } },
    Recipients = new Recipients { Signers = new List<Signer> { signer1, signer2 } },
    Status = "Sent",
};

return envelopeDefinition;
        }
```

**`Java`**

```java title="Java"
EnvelopeDefinition envelope = UseConditionalRecipientsService.createEnvelope(
        args.getSignerNotCheckedName(),
        args.getSignerNotCheckedEmail(),
        args.getSignerCheckedName(),
        args.getSignerCheckedEmail(),
        args.getSignerName(),
        args.getSignerEmail()
);
    public static EnvelopeDefinition createEnvelope(
    String signerNotCheckedName,
    String signerNotCheckedEmail,
    String signerCheckedName,
    String signerCheckedEmail,
    String signerName,
    String signerEmail) throws IOException {
Document document = EnvelopeHelpers.createDocumentFromFile(DOCUMENT_FILE_NAME, DOCUMENT_NAME, DOCUMENT_ID);

WorkflowStep workflowStep = new WorkflowStep();
workflowStep.setAction(EnvelopeHelpers.WORKFLOW_STEP_ACTION_PAUSE);
workflowStep.setTriggerOnItem(EnvelopeHelpers.WORKFLOW_TRIGGER_ROUTING_ORDER);
workflowStep.setItemId("2");
workflowStep.setStatus("pending");
workflowStep.setRecipientRouting(createRecipientRouting(
        signerNotCheckedName,
        signerNotCheckedEmail,
        signerCheckedName,
        signerCheckedEmail));

Workflow workflow = new Workflow();
workflow.setWorkflowSteps(Collections.singletonList(workflowStep));

Recipients recipients = new Recipients();
recipients.setSigners(Arrays.asList(
        createApprovalSigner(document.getDocumentId()),
        createPurchaserSigner(signerName, signerEmail, document.getDocumentId())));

EnvelopeDefinition envelope = new EnvelopeDefinition();
envelope.setEmailSubject("ApproveIfChecked");
envelope.setDocuments(Collections.singletonList(document));
envelope.setStatus(EnvelopeHelpers.ENVELOPE_STATUS_SENT);
envelope.setRecipients(recipients);
envelope.setWorkflow(workflow);

return envelope;
    }

    private static Signer createPurchaserSigner(
    String signerName,
    String signerEmail,
    String documentId) {
SignHere signHere = new SignHere();
signHere.setName("SignHereTabs");
signHere.setXPosition("200");
signHere.setYPosition("200");
signHere.setTabLabel("PurchaserSignature");
signHere.setPageNumber("1");
signHere.setDocumentId(documentId);

Checkbox checkbox = new Checkbox();
checkbox.setName("ClickToApprove");
checkbox.setSelected("false");
checkbox.setXPosition("50");
checkbox.setYPosition("50");
checkbox.setTabLabel("ApproveWhenChecked");
checkbox.setPageNumber("1");
checkbox.setDocumentId(documentId);

Tabs tabs = EnvelopeHelpers.createSignerTabs(signHere);
tabs.setCheckboxTabs(Collections.singletonList(checkbox));

Signer signer = new Signer();
signer.setName(signerName);
signer.setEmail(signerEmail);
signer.setRoutingOrder("1");
signer.setRecipientId("1");
signer.setRoleName("Purchaser");
signer.setTabs(tabs);

return signer;
    }

    private static Signer createApprovalSigner(String documentId) {
SignHere signHere = new SignHere();
signHere.setName("SignHere");
signHere.setRecipientId("2");
signHere.setXPosition("200");
signHere.setYPosition("300");
signHere.setTabLabel("ApproverSignature");
signHere.setPageNumber("1");
signHere.setDocumentId(documentId);

Signer signer = new Signer();
signer.setName("Approver");
signer.setEmail("placeholder@example.com");
signer.setRoutingOrder("2");
signer.setRecipientId("2");
signer.setRoleName("Approver");
signer.setTabs(EnvelopeHelpers.createSignerTabs(signHere));
return signer;
    }

    private static List<ConditionalRecipientRuleCondition> createConditionalRecipientRuleConditions() {

ConditionalRecipientRuleFilter filter1 = new ConditionalRecipientRuleFilter();
filter1.setRecipientId("1");
filter1.setScope("tabs");
filter1.setTabId("ApprovalTab");
filter1.setOperator("equals");
filter1.setValue("false");
filter1.setTabType("checkbox");
filter1.setTabLabel("ApproveWhenChecked");

ConditionalRecipientRuleFilter filter2 = new ConditionalRecipientRuleFilter();
filter2.setRecipientId("1");
filter2.setScope("tabs");
filter2.setTabId("ApprovalTab");
filter2.setOperator("equals");
filter2.setValue("true");
filter2.setTabType("checkbox");
filter2.setTabLabel("ApproveWhenChecked");

ConditionalRecipientRuleCondition condition1 = new ConditionalRecipientRuleCondition();
condition1.setRecipientLabel("signer2a");
condition1.setOrder("1");
condition1.setFilters(Collections.singletonList(filter1));

ConditionalRecipientRuleCondition condition2 = new ConditionalRecipientRuleCondition();
condition2.setRecipientLabel("signer2b");
condition2.setOrder("2");
condition2.setFilters(Collections.singletonList(filter2));
return Arrays.asList(condition1, condition2);
    }

    private static RecipientGroup createRecipientGroup(
    String signerNotCheckedName,
    String signerNotCheckedEmail,
    String signerCheckedName,
    String signerCheckedEmail) {
RecipientOption recipientOption1 = new RecipientOption();
recipientOption1.setRecipientLabel("signer2a");
recipientOption1.setName(signerNotCheckedName);
recipientOption1.setRoleName("Signer when not checked");
recipientOption1.setEmail(signerNotCheckedEmail);

RecipientOption recipientOption2 = new RecipientOption();
recipientOption2.setRecipientLabel("signer2b");
recipientOption2.setName(signerCheckedName);
recipientOption2.setRoleName("Signer when checked");
recipientOption2.setEmail(signerCheckedEmail);

RecipientGroup recipientGroup = new RecipientGroup();
recipientGroup.setGroupName("Approver");
recipientGroup.setGroupMessage("Members of this group approve a workflow");
recipientGroup.setRecipients(Arrays.asList(recipientOption1, recipientOption2));
return recipientGroup;
    }

    private static ConditionalRecipientRule createConditionalRecipientRule(
    String signerNotCheckedName,
    String signerNotCheckedEmail,
    String signerCheckedName,
    String signerCheckedEmail) {
ConditionalRecipientRule conditionalRecipientRule = new ConditionalRecipientRule();
conditionalRecipientRule.setRecipientId("2");
conditionalRecipientRule.setOrder("0");
conditionalRecipientRule.setRecipientGroup(createRecipientGroup(
        signerNotCheckedName,
        signerNotCheckedEmail,
        signerCheckedName,
        signerCheckedEmail));
conditionalRecipientRule.setConditions(createConditionalRecipientRuleConditions());
return conditionalRecipientRule;
    }

    private static RecipientRouting createRecipientRouting(
    String signerNotCheckedName,
    String signerNotCheckedEmail,
    String signerCheckedName,
    String signerCheckedEmail) {
RecipientRules recipientRules = new RecipientRules();
recipientRules.setConditionalRecipients(Collections.singletonList(createConditionalRecipientRule(
        signerNotCheckedName,
        signerNotCheckedEmail,
        signerCheckedName,
        signerCheckedEmail)));

RecipientRouting recipientRouting = new RecipientRouting();
recipientRouting.setRules(recipientRules);
return recipientRouting;
    }
```

**`Node.js`**

```javascript title="Node.js"
const makeEnvelope = (args) => {
  // Step 2. Construct the request body

  // Read and encode file. Put encoded value to Document entity.
  // The reads could raise an exception if the file is not available!
  const documentTxtExample = fs.readFileSync(args.docFile);
  const encodedExampleDocument =
    Buffer.from(documentTxtExample).toString('base64');
  const document = docusign.Document.constructFromObject({
    documentBase64: encodedExampleDocument,
    name: 'Welcome',
    fileExtension: 'txt',
    documentId: 1
  });

  // Create signHere fields (also known as tabs) on the documents
  const signHere1 = docusign.SignHere.constructFromObject({
    documentId: 1,
    pageNumber: 1,
    tabLabel: 'Sign Here',
    xPosition: 200,
    yPosition: 200
  });
  const signHere2 = docusign.SignHere.constructFromObject({
    documentId: 1,
    pageNumber: 1,
    tabLabel: ' Sign Here',
    recipientId: 2,
    xPosition: 300,
    yPosition: 200
  });

  // Create checkbox field on the documents
  const checkbox = docusign.Checkbox.constructFromObject({
    documentId: 1,
    pageNumber: 1,
    name: 'ClickToApprove',
    selected: false,
    tabLabel: 'ApproveWhenChecked',
    xPosition: 50,
    yPosition: 50
  });

  // Create the signer recipient models
  // Also add the tabs model (including the sign_here tabs) to the signer
  const signer1 = docusign.Signer.constructFromObject({
    email: args['signer1Email'],
    name: args['signer1Name'],
    recipientId: 1,
    routingOrder: 1,
    roleName: 'Purchaser',
    tabs: docusign.Tabs.constructFromObject({
      signHereTabs: [signHere1],
      checkboxTabs: [checkbox]
    })
  });
  const signer2 = docusign.Signer.constructFromObject({
    name: 'Approver',
    recipientId: 2,
    routingOrder: 2,
    roleName: 'Approver',
    tabs: docusign.Tabs.constructFromObject({
      signHereTabs: [signHere2]
    })
  });

  const recipients = docusign.Recipients.constructFromObject({
    signers: [signer1, signer2]
  });

  // Create recipientOption and recipientGroup models
  const signer2a = docusign.RecipientOption.constructFromObject({
    email: args['signer2aEmail'],
    name: args['signer2aName'],
    roleName: 'Signer when not checked',
    recipientLabel: 'signer2a'
  });
  const signer2b = docusign.RecipientOption.constructFromObject({
    email: args['signer2bEmail'],
    name: args['signer2bName'],
    roleName: 'Signer when checked',
    recipientLabel: 'signer2b'
  });
  const recipientGroup = docusign.RecipientGroup.constructFromObject({
    groupName: 'Approver',
    groupMessage: 'Members of this group approve a workflow',
    recipients: [signer2a, signer2b]
  });

  // Create conditionalRecipientRuleFilter models
  const filter1 = docusign.ConditionalRecipientRuleFilter.constructFromObject({
    scope: 'tabs',
    recipientId: 1,
    tabId: 'ApprovalTab',
    operator: 'equals',
    value: false,
    tabLabel: 'ApproveWhenChecked',
    tabType: 'checkbox'
  });
  const filter2 = docusign.ConditionalRecipientRuleFilter.constructFromObject({
    scope: 'tabs',
    recipientId: 1,
    tabId: 'ApprovalTab',
    operator: 'equals',
    value: true,
    tabLabel: 'ApproveWhenChecked',
    tabType: 'checkbox'
  });

  // Create conditionalRecipientRuleCondition models
  const condition1 =
    docusign.ConditionalRecipientRuleCondition.constructFromObject({
      filters: [filter1],
      order: 1,
      recipientLabel: 'signer2a'
    });
  const condition2 =
    docusign.ConditionalRecipientRuleCondition.constructFromObject({
      filters: [filter2],
      order: 2,
      recipientLabel: 'signer2b'
    });

  // Create conditionalRecipientRule model
  const conditionalRecipient =
    docusign.ConditionalRecipientRule.constructFromObject({
      conditions: [condition1, condition2],
      recipientGroup: recipientGroup,
      recipientId: 2,
      order: 0
    });

  // Create recipientRouting model
  const recipientRouting = docusign.RecipientRouting.constructFromObject({
    rules: docusign.RecipientRules.constructFromObject({
      conditionalRecipients: [conditionalRecipient]
    })
  });

  // Create a workflow model
  const workflowStep = docusign.WorkflowStep.constructFromObject({
    action: 'pause_before',
    triggerOnItem: 'routing_order',
    itemId: 2,
    status: 'pending',
    recipientRouting: recipientRouting
  });
  const workflow = docusign.Workflow.constructFromObject({
    workflowSteps: [workflowStep]
  });

  // Request that the envelope be sent by setting status to "sent".
  // To request that the envelope be created as a draft, set status to "created"
  return docusign.EnvelopeDefinition.constructFromObject({
    emailSubject: 'EnvelopeWorkflowTest',
    documents: [document],
    status: args.status,
    workflow,
    recipients
  });
};
```

**`PHP`**

```php title="PHP"
$envelope_definition = UseConditionalRecipientsService::makeEnvelope($envelope_args, $demoDocsPath);
    public static function makeEnvelope($envelope_args, $demoDocsPath): EnvelopeDefinition
    {
# The envelope has two recipients
# Recipient 1 - signer1
# Recipient 2 - signer2
# The envelope will be sent first to the signer1
# After it is signed, a signature workflow will be paused
# After resuming (unpause) the signature workflow will send to the second recipient

# Create the top-level envelope definition
$envelope_definition = new EnvelopeDefinition([
    'email_subject' => "ApproveIfChecked",
]);

# Read the file
$content_bytes = file_get_contents($demoDocsPath . $GLOBALS['DS_CONFIG']['doc_txt']);
$base64_file_content = base64_encode($content_bytes);
# Create the document model
$document = new Document([ # Create the DocuSign document object
    'document_base64' => $base64_file_content,
    'name' => 'Welcome', # Can be different from actual file name
    'file_extension' => 'txt', # Many different document types are accepted
    'document_id' => "1" # A label used to reference the doc
]);

# The order in the docs array determines the order in the envelope.
$envelope_definition->setDocuments([$document, ]);

# Create the signer recipient models
# routing_order (lower means earlier) determines the order of deliveries
# to the recipients.
$signer1 = new Signer([ # The signer1
    'email' => $envelope_args['signer1_email'],
    'name' => $envelope_args['signer1_name'],
    'recipient_id' => "1",
    'routing_order' => "1",
    'role_name' => "Purchaser",
]);

$signer2 = new Signer([ # The signer2
    'email' => "placeholder@example.com",
    'name' => "Approver",
    'recipient_id' => "2",
    'routing_order' => "2",
    'role_name' => "Approver"
]);

# Create SignHere fields (also known as tabs) on the documents.
$sign_here1 = new SignHere([
    'document_id' => "1",
    'page_number' => "1",
    'name' => "SignHere",
    'tab_label' => "PurchaserSignature",
    'x_position' => "200",
    'y_position' => "200",
]);

$sign_here2 = new SignHere([
    'document_id' => "1",
    'page_number' => "1",
    'name' => "SignHere",
    'tab_label' => "ApproverSignature",
    'recipient_id' => "2",
    'x_position' => "300",
    'y_position' => "200",
]);

# Create checkbox field on the documents
$checkbox = new Checkbox([
    'document_id' => "1",
    'page_number' => "1",
    'name' => "ClickToApprove",
    'selected' => "false",
    'tab_label' => "ApproveWhenChecked",
    'x_position' => "50",
    'y_position' => "50",
]);

# Add the tabs model (including the sign_here tabs) to the signer
# The Tabs object takes arrays of the different field/tab types
$signer1->setTabs(
    new Tabs([
        'sign_here_tabs' => [$sign_here1, ],
        'checkbox_tabs' => [$checkbox, ]
    ])
);

$signer2->setTabs(
    new Tabs([
        'sign_here_tabs' => [$sign_here2, ],
    ])
);

# Add the recipients to the envelope object
$env_recipients = new Recipients([
    'signers' => [$signer1, $signer2, ],
]) ;
$envelope_definition->setRecipients($env_recipients);

# Create recipientOption models
$signer_2a = new RecipientOption([ # The signer2
    'email' => $envelope_args['signer_2a_email'],
    'name' => $envelope_args['signer1_2a_name'],
    'role_name' => "Signer when not checked",
    'recipient_label' => "signer2a",
]);

$signer_2b = new RecipientOption([ # The signer2
    'email' => $envelope_args['signer_2b_email'],
    'name' => $envelope_args['signer1_2b_name'],
    'role_name' => "Signer when checked",
    'recipient_label' => "signer2b",
]);

$recipients = [$signer_2a, $signer_2b, ];

# Create recipientGroup model
$recipient_group = new RecipientGroup([
    'group_name' => "Approver",
    'group_message' => "Members of this group approve a workflow",
    'recipients' => $recipients,
]);

# Create conditionalRecipientRuleFilter models
$filter1 = new ConditionalRecipientRuleFilter([
    'scope' => "tabs",
    'recipient_id' => "1",
    'tab_id' => "ApprovalTab",
    'operator' => "equals",
    'value' => "false",
    'tab_type' => "checkbox",
    'tab_label' => "ApproveWhenChecked"
]);

$filter2 = new ConditionalRecipientRuleFilter([
    'scope' => "tabs",
    'recipient_id' => "1",
    'tab_id' => "ApprovalTab",
    'operator' => "equals",
    'value' => "true",
    'tab_type' => 'checkbox',
    'tab_label' => "ApproveWhenChecked"
]);

# Create conditionalRecipientRuleCondition models
$condition1 = new ConditionalRecipientRuleCondition([
    'filters' => [$filter1, ],
    'order' => "1",
    'recipient_label' => "signer2a"
]);
$condition2 = new ConditionalRecipientRuleCondition([
    'filters' => [$filter2, ],
    'order' => "2",
    'recipient_label' => "signer2b"
]);
$conditions = [$condition1, $condition2];

# Create conditionalRecipientRule model
$conditional_recipient = new ConditionalRecipientRule([
    'conditions' => $conditions,
    'recipient_group' => $recipient_group,
    'recipient_id' => "2",
    'order' => "0",

]);

# Create recipientRules model
$rules = new RecipientRules(['conditional_recipients' => [$conditional_recipient, ]]);
$recipient_routing = new RecipientRouting(['rules' => $rules]);

# Create a workflow model
$workflow_step = new WorkflowStep([
    'action' => "pause_before",
    'trigger_on_item' => "routing_order",
    'item_id' => "2",
    'status' => "pending",
    'recipient_routing' => $recipient_routing,
]);

# Create a workflow model
$workflow = new Workflow([
    'workflow_steps' => [$workflow_step, ],
]);
# Add the workflow to the envelope object
$envelope_definition->setWorkflow($workflow);

# Request that the envelope be sent by setting |status| to "sent"
# To request that the envelope be created as a draft, set to "created"
$envelope_definition->setStatus($envelope_args['status']);
return $envelope_definition;
    }
```

**`PowerShell`**

```text title="PowerShell"
@{
    documents    =
    @(
        @{
            documentBase64 = "VGhhbmtzIGZvciByZXZpZXdpbmcgdGhpcyEKCldlJ2xsIG1vdmUgZm9yd2FyZCBhcyBzb29uIGFzIHdlIGhlYXIgYmFjay4=";
            documentId     = "1";
            fileExtension  = "txt";
            name           = "Welcome"
        };
    );
    emailSubject = "ApproveIfChecked";
    workflow     =
    @{
        workflowSteps =
        @(
            @{
                action           = "pause_before";
                triggerOnItem    = "routing_order";
                itemId           = 2;
                status           = "pending";
                recipientRouting =
                @{
                    rules =
                    @{
                        conditionalRecipients =
                        @(
                            @{
                                recipientId    = 2;
                                order          = "0";
                                recipientGroup =
                                @{
                                    groupName    = "Approver";
                                    groupMessage = "Members of this group approve a workflow";
                                    recipients   =
                                    @(
                                        @{
                                            recipientLabel = "signer2a";
                                            name           = $SIGNER_NOT_CHECKED_NAME;
                                            roleName       = "Signer when not checked";
                                            email          = $SIGNER_NOT_CHECKED_EMAIL
                                        };
                                        @{
                                            recipientLabel = "signer2b";
                                            name           = $SIGNER_WHEN_CHECKED_NAME;
                                            roleName       = "Signer when checked";
                                            email          = $SIGNER_WHEN_CHECKED_EMAIL
                                        };
                                    );
                                };
                                conditions     =
                                @(
                                    @{
                                        recipientLabel = "signer2a";
                                        order          = 1;
                                        filters        =
                                        @(
                                            @{
                                                scope       = "tabs";
                                                recipientId = "1";
                                                tabId       = "ApprovalTab";
                                                operator    = "equals";
                                                value       = "false";
                                                tabType     = "checkbox";
                                                tabLabel    = "ApproveWhenChecked"
                                            };
                                        );
                                    };
                                    @{
                                        recipientLabel = "signer2b";
                                        order          = 2;
                                        filters        =
                                        @(
                                            @{
                                                scope       = "tabs";
                                                recipientId = "1";
                                                tabId       = "ApprovalTab";
                                                operator    = "equals";
                                                value       = "true";
                                                tabType     = "checkbox";
                                                tabLabel    = "ApproveWhenChecked"
                                            };
                                        );
                                    };
                                );
                            };
                        );
                    };
                };
            };
        );
    };
    recipients   =
    @{
        signers =
        @(
            @{
                email        = $SIGNER1_EMAIL;
                name         = $SIGNER1_NAME;
                recipientId  = "1";
                routingOrder = "1";
                roleName     = "Purchaser";
                tabs         =
                @{
                    signHereTabs =
                    @(
                        @{
                            name       = "SignHere";
                            documentId = "1";
                            pageNumber = "1";
                            tabLabel   = "PurchaserSignature";
                            xPosition  = "200";
                            yPosition  = "200"
                        };
                    );
                    checkboxTabs =
                    @(
                        @{
                            name       = "ClickToApprove";
                            selected   = "false";
                            documentId = "1";
                            pageNumber = "1";
                            tabLabel   = "ApproveWhenChecked";
                            xPosition  = "50";
                            yPosition  = "50"
                        };
                    );
                };
            };
            @{
                email        = "placeholder@example.com";
                name         = "Approver";
                recipientId  = "2";
                routingOrder = "2";
                roleName     = "Approver";
                tabs         =
                @{
                    signHereTabs =
                    @(
                        @{
                            name        = "SignHere";
                            documentId  = "1";
                            pageNumber  = "1";
                            recipientId = "2";
                            tabLabel    = "ApproverSignature";
                            xPosition   = "300";
                            yPosition   = "200"
                        };
                    );
                };
            };
        );
    };
    status       = "Sent"
} | ConvertTo-Json -Depth 32 > $requestData
```

**`Python`**

```python title="Python"
# Create the envelope definition
env = EnvelopeDefinition(email_subject="ApproveIfChecked")

# Read file from a local directory
# The reads could raise an exception if the file is not available
with open(path.join(demo_docs_path, DS_CONFIG["doc_txt"]),
          "rb") as file:
    doc_docx_bytes = file.read()
doc_b64 = base64.b64encode(doc_docx_bytes).decode("ascii")

# Create the document model.
document = Document(  # Create the DocuSign document object
    document_base64=doc_b64,
    name="Welcome",  # Can be different from actual file name
    file_extension="txt",  # Many different document types are accepted
    document_id="1"  # A label used to reference the doc
)
env.documents = [document, ]

# Create the signer model
# routingOrder (lower means earlier) determines the order of deliveries to the recipients
signer1 = Signer(
    email=args["signer1_email"],
    name=args["signer1_name"],
    recipient_id="1",
    routing_order="1",
    role_name="Purchaser"
)
signer2 = Signer(
    email="placeholder@example.com",
    name="Approver",
    recipient_id="2",
    routing_order="2",
    role_name="Approver"
)

# Create signHere fieldы (also known as tabs) on the documents
sign_here1 = SignHere(
    document_id="1",
    page_number="1",
    name="SignHere",
    tab_label="PurchaserSignature",
    x_position="200",
    y_position="200"
)
sign_here2 = SignHere(
    document_id="1",
    page_number="1",
    name="SignHere",
    recipient_id="2",
    tab_label="ApproverSignature",
    x_position="300",
    y_position="200"
)

# Create checkbox field on the documents
checkbox = Checkbox(
    document_id="1",
    page_number="1",
    name="ClickToApprove",
    selected="false",
    tab_label="ApproveWhenChecked",
    x_position="50",
    y_position="50"
)

# Add the tabs models (including the sign_here tabs) to the signer
# The Tabs object wants arrays of the different field/tab types
signer1.tabs = Tabs(
    sign_here_tabs=[sign_here1, ],
    checkbox_tabs=[checkbox, ]
)
signer2.tabs = Tabs(sign_here_tabs=[sign_here2, ])

# Add the recipients to the envelope object
env_recipients = Recipients(signers=[signer1, signer2])
# env_recipients = Recipients(signers=[signer1, ])
env.recipients = env_recipients

# Create recipientOption models
signer_2a = RecipientOption(
    email=args["signer_2a_email"],
    name=args["signer_2a_name"],
    role_name="Signer when not checked",
    recipient_label="signer2a"
)
signer_2b = RecipientOption(
    email=args["signer_2b_email"],
    name=args["signer_2b_name"],
    role_name="Signer when checked",
    recipient_label="signer2b"
)
recipients = [signer_2a, signer_2b]

# Create recipientGroup model
recipient_group = RecipientGroup(
    group_name="Approver",
    group_message="Members of this group approve a workflow",
    recipients=recipients
)

# Create conditionalRecipientRuleFilter models
filter1 = ConditionalRecipientRuleFilter(
    scope="tabs",
    recipient_id="1",
    tab_id="ApprovalTab",
    operator="equals",
    value="false",
    tab_label="ApproveWhenChecked",
    tab_type ="checkbox"
)
filter2 = ConditionalRecipientRuleFilter(
    scope="tabs",
    recipient_id="1",
    tab_id="ApprovalTab",
    operator="equals",
    value="true",
    tab_label="ApproveWhenChecked",
    tab_type ="checkbox"
)

# Create conditionalRecipientRuleCondition models
condition1 = ConditionalRecipientRuleCondition(
    filters=[filter1, ],
    order="1",
    recipient_label="signer2a"
)
condition2 = ConditionalRecipientRuleCondition(
    filters=[filter2, ],
    order="2",
    recipient_label="signer2b"
)
conditions = [condition1, condition2]

# Create conditionalRecipientRule model
conditional_recipient = ConditionalRecipientRule(
    conditions=conditions,
    recipient_group=recipient_group,
    recipient_id="2",
    order="0",

)

# Create recipientRules model
rules = RecipientRules(conditional_recipients=[conditional_recipient, ])
recipient_routing = RecipientRouting(rules=rules)

# Create a workflow model
workflow_step = WorkflowStep(
    action="pause_before",
    trigger_on_item="routing_order",
    item_id="2",
    status="pending",
    recipient_routing=recipient_routing
)
workflow = Workflow(workflow_steps=[workflow_step, ])
# Add the workflow to the envelope object
env.workflow = workflow

# Request that the envelope be sent by setting |status| to "sent"
# To request that the envelope be created as a draft, set to "created"
env.status = args["status"]
return env
```

**`Ruby`**

```ruby title="Ruby"
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new(emailSubject: 'ApproveIfChecked')

# Create the document model.
documents = [
  DocuSign_eSign::Document.new(
    documentBase64: 'VGhhbmtzIGZvciByZXZpZXdpbmcgdGhpcyEKCldlJ2xsIG1vdmUgZm9yd2FyZCBhcyBzb29uIGFzIHdlIGhlYXIgYmFjay4=',
    documentId: 1,
    fileExtension: 'txt',
    name: 'Welcome'
  )
]
envelope_definition.documents = documents

# Create the signer model
# routingOrder (lower means earlier) determines the order of deliveries to the recipients
signer_1 = DocuSign_eSign::Signer.new(
  email: signers[:signerEmail1],
  name: signers[:signerName1],
  recipientId: 1,
  routingOrder: 1,
  roleName: 'Purchaser'
)
signer_2 = DocuSign_eSign::Signer.new(
  email: 'placeholder@example.com',
  name: 'Approver',
  recipientId: 2,
  routingOrder: 2,
  roleName: 'Approver'
)

# Create signHere field (also known as tabs) on the documents
sign_here_1 = DocuSign_eSign::SignHere.new(
  documentId: 1,
  pageNumber: 1,
  name: 'SignHere',
  tabLabel: 'PurchaserSignature',
  xPosition: 200,
  yPosition: 200
)
sign_here_2 = DocuSign_eSign::SignHere.new(
  documentId: 1,
  pageNumber: 1,
  name: 'SignHere',
  recipientId: 2,
  tabLabel: 'ApproverSignature',
  xPosition: 300,
  yPosition: 200
)

# Create checkbox field on the documents
checkbox = DocuSign_eSign::Checkbox.new(
  documentId: 1,
  pageNumber: 1,
  name: 'ClickToApprove',
  selected: false,
  tabLabel: 'ApproveWhenChecked',
  xPosition: 50,
  yPosition: 50
)

# Add the tabs models (including the sign_here tabs) to the signer
# The Tabs object wants arrays of the different field/tab types
signer_1.tabs = DocuSign_eSign::Tabs.new(
  signHereTabs: [sign_here_1],
  checkboxTabs: [checkbox]
)
signer_2.tabs = DocuSign_eSign::Tabs.new(
  signHereTabs: [sign_here_2]
)

# Add the recipients to the envelope object
env_recipients = DocuSign_eSign::Recipients.new(signers: [signer_1, signer_2])
envelope_definition.recipients = env_recipients

# Create recipientOption models
signer_2a = DocuSign_eSign::RecipientOption.new(
  email: signers[:signerEmailNotChecked],
  name: signers[:signerNameNotChecked],
  roleName: 'Signer when not checked',
  recipientLabel: 'signer2a'
)
signer_2b = DocuSign_eSign::RecipientOption.new(
  email: signers[:signerEmailChecked],
  name: signers[:signerNameChecked],
  roleName: 'Signer when checked',
  recipientLabel: 'signer2b'
)
recipients = [signer_2a, signer_2b]

# Create recipientGroup model
recipient_group = DocuSign_eSign::RecipientGroup.new(
  groupName: 'Approver',
  groupMessage: 'Members of this group approve a workflow',
  recipients: recipients
)

# Create conditionalRecipientRuleFilter models
filter1 = DocuSign_eSign::ConditionalRecipientRuleFilter.new(
  scope: 'tabs',
  recipientId: 1,
  tabId: 'ApprovalTab',
  operator: 'equals',
  value: false,
  tabLabel: 'ApproveWhenChecked',
  tabType: 'checkbox'
)
filter2 = DocuSign_eSign::ConditionalRecipientRuleFilter.new(
  scope: 'tabs',
  recipientId: 1,
  tabId: 'ApprovalTab',
  operator: 'equals',
  value: true,
  tabLabel: 'ApproveWhenChecked',
  tabType: 'checkbox'
)

# Create conditionalRecipientRuleCondition models
condition1 = DocuSign_eSign::ConditionalRecipientRuleCondition.new(
  filters: [filter1],
  order: 1,
  recipientLabel: 'signer2a'
)
condition2 = DocuSign_eSign::ConditionalRecipientRuleCondition.new(
  filters: [filter2],
  order: 2,
  recipientLabel: 'signer2b'
)
conditions = [condition1, condition2]

# Create conditionalRecipientRule model
conditional_recipient = DocuSign_eSign::ConditionalRecipientRule.new(
  conditions: conditions,
  recipientGroup: recipient_group,
  recipientId: 2,
  order: 0
)

# Create recipientRules model
rules = DocuSign_eSign::RecipientRules.new(conditionalRecipients: [conditional_recipient])
recipient_routing = DocuSign_eSign::RecipientRouting.new(rules: rules)

# Create a workflow model
workflow_step = DocuSign_eSign::WorkflowStep.new(
  action: 'pause_before',
  triggerOnItem: 'routing_order',
  itemId: 2,
  status: 'pending',
  recipientRouting: recipient_routing
)
workflow = DocuSign_eSign::Workflow.new(workflowSteps: [workflow_step])
# Add the workflow to the envelope object
envelope_definition.workflow = workflow

# Request that the envelope be sent by setting |status| to "sent"
# To request that the envelope be created as a draft, set to "created"
envelope_definition.status = 'sent'
```

## Step 4. Call the eSignature REST API

Now that you have constructed your API headers and envelope body, make a request to the [Envelopes:create](/docs/esign-rest-api/reference/envelopes/envelopes/create) endpoint and include the JSON body to create a new envelope with the conditional routing criteria you have selected.

Here's how you make the call, but make sure to substitute your API account ID for \{ACCOUNT_ID}.

> **Note**
>
> View the source code for this how-to on GitHub: [Bash](https://github.com/docusign/code-examples-bash/blob/master/examples/eSignature/eg034UseConditionalRecipients.sh), [C#](https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/eSignature/Examples/ConditionalRecipientsWorkflow.cs), [Java](https://github.com/docusign/code-examples-java/blob/master/src/main/java/com/docusign/controller/eSignature/services/UseConditionalRecipientsService.java), [Node.js](https://github.com/docusign/code-examples-node/blob/master/lib/eSignature/examples/useConditionalRecipients.js), [PHP](https://github.com/docusign/code-examples-php/blob/master/src/Services/Examples/eSignature/UseConditionalRecipientsService.php), [PowerShell](https://github.com/docusign/code-examples-powershell/blob/main/examples/eSignature/eg034UseConditionalRecipients.ps1), [Python](https://github.com/docusign/code-examples-python/blob/master/app/eSignature/examples/eg034_use_conditional_recipients.py), [Ruby](https://github.com/docusign/code-examples-ruby/blob/main/app/services/e_sign/eg034_use_conditional_recipients_service.rb).

**`Bash`**

```bash title="Bash"
Status=$(curl --request POST "${base_path}/v2.1/accounts/${account_id}/envelopes" \
  "${Headers[@]}" \
  --data-binary @${request_data} \
  --output ${response})
```

**`C#`**

```csharp title="C#"
var response = envelopesApi.CreateEnvelopeWithHttpInfo(accountId, envelope);

response.Headers.TryGetValue("X-RateLimit-Remaining", out string remaining);
response.Headers.TryGetValue("X-RateLimit-Reset", out string reset);

if (reset != null && remaining != null)
{
    DateTime resetDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(reset)).UtcDateTime;
    Console.WriteLine("API calls remaining: " + remaining);
    Console.WriteLine("Next Reset: " + resetDate);
}

return response.Data;
```

**`Java`**

```java title="Java"
public static EnvelopeSummary useConditionalRecipients(
        EnvelopesApi envelopesApi,
        String accountId,
        EnvelopeDefinition envelope) throws ApiException {
    var createEnvelopeResponse = envelopesApi.createEnvelopeWithHttpInfo(accountId, envelope,
            envelopesApi.new CreateEnvelopeOptions());
    Map<String, List<String>> headers = createEnvelopeResponse.getHeaders();
    java.util.List<String> remaining = headers.get("X-RateLimit-Remaining");
    java.util.List<String> reset = headers.get("X-RateLimit-Reset");

    if (remaining != null & reset != null) {
        Instant resetInstant = Instant.ofEpochSecond(Long.parseLong(reset.get(0)));
        System.out.println("API calls remaining: " + remaining);
        System.out.println("Next Reset: " + resetInstant);
    }
    return createEnvelopeResponse.getData();
}
```

**`Node.js`**

```javascript title="Node.js"
const envelopesApi = new docusign.EnvelopesApi(dsApiClient);
const envelope = await envelopesApi.createEnvelope(args.accountId, {
  envelopeDefinition,
}, (error, data, response) => {
    const headers = response?.headers;

    const remaining = headers?.['x-ratelimit-remaining'];
    const reset = headers?.['x-ratelimit-reset'];

    if (remaining && reset) {
      const resetInstant = new Date(Number(reset) * 1000);

      console.log(`API calls remaining: ${remaining}`);
      console.log(`Next Reset: ${resetInstant.toISOString()}`);
    }
});
```

**`PHP`**

```php title="PHP"
$envelope = $envelope_api->createEnvelopeWithHttpInfo($args["account_id"], $envelope_definition);

$remaining = $envelope[2]['X-RateLimit-Remaining'] ?? null;
$reset =  $envelope[2]['X-RateLimit-Reset'] ?? null;

if ($remaining !== null && $reset !== null) {
    $resetInstant = (new DateTime())->setTimestamp((int)$reset);
    error_log("API calls remaining: $remaining");
    error_log("Next Reset: " . $resetInstant->format(\DateTime::ATOM));
}
```

**`PowerShell`**

```text title="PowerShell"
try {
    Write-Output "Request: "
    Write-Output $requestData
    $uri = "https://demo.docusign.net/restapi/v2.1/accounts/${APIaccountId}/envelopes"
    Invoke-RestMethod `
        -Uri $uri `
        -Method 'POST' `
        -Headers @{
        'Authorization' = "Bearer $oAuthAccessToken";
        'Content-Type'  = "application/json";
    } `
        -InFile (Resolve-Path $requestData).Path `
        -OutFile $response

    Write-Output "Response: $(Get-Content -Raw $response)"
}
catch [System.Net.WebException] {
    $errorCode = $($_.ErrorDetails | ConvertFrom-Json).errorCode
    if ( $errorCode -eq "WORKFLOW_UPDATE_RECIPIENTROUTING_NOT_ALLOWED" ) {
        Write-Output ""
        Write-Output "The following Error happened: WORKFLOW_UPDATE_RECIPIENTROUTING_NOT_ALLOWED"
        Write-Output "Please contact Docusign support..."
    }
    else {
        $_
    }
}
catch {
    Write-Output $_
}
```

**`Python`**

```python title="Python"
envelopes_api = EnvelopesApi(api_client)
(results, status, headers) = envelopes_api.create_envelope_with_http_info(
    account_id=args["account_id"],
    envelope_definition=envelope_definition
)

remaining = headers.get("X-RateLimit-Remaining")
reset = headers.get("X-RateLimit-Reset")

if remaining is not None and reset is not None:
    reset_date = dt.fromtimestamp(int(reset), tz=timezone.utc)
    print(f"API calls remaining: {remaining}")
    print(f"Next Reset: {reset_date}")
```

**`Ruby`**

```ruby title="Ruby"
envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client)

results, _status, headers = envelopes_api.create_envelope_with_http_info(
  args[:accountId],
  envelope_definition
)

remaining = headers['X-RateLimit-Remaining']
reset = headers['X-RateLimit-Reset']

if remaining && reset
  reset_date = Time.at(reset.to_i).utc
  puts "API calls remaining: #{remaining}"
  puts "Next Reset: #{reset_date}"
end
```

## 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.

**`Sample response`**

```json title="Sample response"
{
  "envelopeId": "74baaa91-xxxx-xxxx-xxxx-929b02f47fd1",
  "uri": "/envelopes/74baaa91-xxxx-xxxx-xxxx-929b02f47fd1",
  "statusDateTime": "2020-08-08T05:24:13.5370000Z",
  "status": "sent"
}
```

## 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), [PHP](https://github.com/docusign/code-examples-php), [PowerShell](https://github.com/docusign/code-examples-powershell), [Python](https://github.com/docusign/code-examples-python), or [Ruby](https://github.com/docusign/code-examples-ruby).
* Learn more about [Advanced Recipient Routing (ARR)](/docs/esign-rest-api/esign101/concepts/recipients/pause-unpause-workflow).
* See all available eSignature [How-to guides](/docs/esign-rest-api/how-to).
* See [How to pause a signature workflow](/docs/esign-rest-api/how-to/pause-workflow).
* See how to [Go-Live](/docs/esign-rest-api/go-live) with a completed app and find the base path for API calls in the production environment.