Skip to navigation

How to require phone authentication for a recipient

View as Markdown
eSignature REST API 2.1 only

This topic demonstrates how to request a signature via email while also using phone authentication.

Run this code example from our Quickstart or launcher projects: Bash, C#, Java, Node.js, PHP, PowerShell, Python, or Ruby.

Required data

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

Data elementDescription
{API_ACCOUNT_ID}A GUID 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 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.
{COUNTRY_CODE}The country code corresponding to the PHONE_NUMBER.
{DOCUMENT_ID}A document identifier such as a name or ID. You can get a list of envelope documents to obtain this information.
Document to be signedYou must provide at least one document to be signed. Document used in this how-to:
{PHONE_NUMBER}The phone number of the signer where the authentication message will be sent.
{RECIPIENT_ID}A unique string value that you assign to identify each recipient. This value assigns tabs on a per-recipient basis.
{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 the identity verification workflow assigned to your account when phone authentication is enabled.

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

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

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

Step 3. Obtain your workflow ID

Make a request to the IdentityVerifications:list endpoint on the Accounts resource of the eSignature REST API using your {API_ACCOUNT_ID} to retrieve the workflow ID. The response will include an array of workflow IDs. Different workflow IDs can be specified per recipient. To require phone authentication for a given recipient, use the workflow ID with the name “Phone Authentication.” If you do not have phone authentication configured for your account, the identity_verification call will return an empty array. Omitting a workflow ID or providing an invalid workflow ID will cause your request to fail.

Status=$(curl -w '%{http_code}' -i --request GET "https://demo.docusign.net/restapi/v2.1/accounts/${account_id}/identity_verification" \
"${Headers[@]}" \
--output ${response})
#If the Status code returned is greater than 201 (OK / Accepted), display an error message along with the API response.
if [[ "$Status" -gt "201" ]] ; then
echo ""
echo "Unable to retrieve your account's workflow ID."
echo ""
cat $response
exit 0
fi
echo ""
echo "Response:"
cat $response
echo ""
# Retrieve the workflow IDs from the API response and put them in an array.
workflowIds=`cat $response | grep -o -P '(?<=workflowId\":\").*?(?=\")'`
arrWorkflowIds=($workflowIds)
# Get the index of the Phone auth workflow based on name and use that index for workflowId.
# Workflow name of phone auth is 'Phone Authentication'
workflowNames=`cat $response | grep -o -P '(?<=defaultName\":).*?(?=,)'`
element="Phone Authentication"
workflowId=$(GetWorkflowId "$workflowNames" "$element" "$workflowIds")

Step 4. Construct the request body

Next, create the request body. To create an envelope using the eSignature REST API, you need to construct an envelope body in JSON format. Replace {RECIPIENT_ID}, {SIGNER_NAME}, {SIGNER_EMAIL}, {COUNTRY_CODE}, and {PHONE_NUMBER} with your recipient’s data in the JSON request body.

The accompanying code demonstrates how to use the identityVerification property in the request body to require phone authentication for a given recipient. In your developer account, use the workflow ID from the previous step to specify the phone authentication workflow.

printf \
'{
"documents": [{
"documentBase64": "' > $request_data
cat $doc1_base64 >> $request_data
printf '",
"name": "Lorem Ipsum",
"fileExtension": "pdf",
"documentId": "1"
}],
"emailBlurb": "Sample text for email body",
"emailSubject": "Please Sign",
"envelopeIdStamping": "true",
"recipients": {
"signers": [{
"name": "'"${RECIPIENT_NAME}"'",
"email": "'"${RECIPIENT_EMAIL}"'",
"note": "",
"routingOrder": "1",
"status": "created",
"tabs": {
"signHereTabs": [{
"documentId": "1",
"name": "SignHereTab",
"pageNumber": "1",
"recipientId": "1",
"tabLabel": "SignHereTab",
"xPosition": "200",
"yPosition": "170"
}]
},
"templateAccessCodeRequired": null,
"deliveryMethod": "email",
"recipientId": "1",
"identityVerification":{
"workflowId":"'"${workflowId}"'",
"steps":null,"inputOptions":[
{"name":"phone_number_list",
"valueType":"PhoneNumberList",
"phoneNumberList":[
{
"countryCode":"'"${SIGNER_PHONE_COUNTRY}"'",
"number":"'"${SIGNER_PHONE_NUMBER}"'"
}
]
}]
}
}]
},
"status": "Sent"
}
' >> $request_data

Step 5. Call the eSignature REST API

Now that you have constructed your API headers and request body, you can send the envelope with the Envelopes:create method. Here’s how you make the call, but make sure to substitute your API account ID for {ACCOUNT_ID}.

View the source code for this how-to on GitHub: Bash, C#, Java, Node.js, PHP, PowerShell, Python, or Ruby.

curl --request POST "https://demo.docusign.net/restapi/v2.1/accounts/${account_id}/envelopes" \
"${Headers[@]}" \
--data-binary @${request_data} \
--output ${response}

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
{
"documents": [
{
"documentBase64": "JVBERi...VPRgo=",
"name": "Lorem Ipsum",
"fileExtension": "pdf",
"documentId": "1"
}
],
"emailBlurb": "Sample text for email body",
"emailSubject": "Please Sign",
"envelopeIdStamping": "true",
"recipients": {
"signers": [
{
"name": "Susan Signer",
"email": "test@example.com",
"roleName": "",
"note": "",
"routingOrder": 3,
"status": "created",
"tabs": {
"signHereTabs": [
{
"documentId": "1",
"name": "SignHereTab",
"pageNumber": "1",
"recipientId": "1",
"tabLabel": "SignHereTab",
"xPosition": "75",
"yPosition": "572"
}
]
},
"templateAccessCodeRequired": null,
"deliveryMethod": "email",
"recipientId": "1",
"identityVerification": {
"workflowId": "c368e411-xxxx-xxxx-xxxx-dca94ac539ae",
"steps": null,
"inputOptions": [
{
"name": "phone_number_list",
"valueType": "PhoneNumberList",
"phoneNumberList": [
{
"countryCode": "1",
"number": "4155551212"
}
]
}
]
}
}
]
},
"status": "Sent"
}

Next steps