Skip to main content
Question

Docusign (PHP SDK) Envelope Creation: RECIPIENTS_NOT_PROVIDED

  • 10 May 2024
  • 2 replies
  • 158 views

 

I'm attempting to create a Docusign envelope from a template using the PHP sdk e-sign client:

$apiClient = new ApiClient($config);

// Create an Envelope from a template
$templateId = env('TEMPLATE_ID');
$accountId = env('API_ACCOUNT_ID');
$envelopeApi = new EnvelopesApi($apiClient);
$templateRole = new TemplateRole((
'email' => 'john@example.com', // recipient's email
'name' => 'John Doe', // recipient's name
'roleName' => 'User', // The role name as defined in the template
]);

$envelopeDefinition = new EnvelopeDefinition((
'status' => 'sent',
'templateId' => $templateId,
'templateRoles' => $templateRole]
]);
$envelopeSummary = $envelopeApi->createEnvelope($accountId, $envelopeDefinition);

Produces: Error while requesting server, received a non successful HTTP code 400] with response: RECIPIENTS_NOT_PROVIDED - No recipients were found in the request

From the logs I can see this uses the endpoint POST /restapi/v2.1/accounts/{accountId}/envelopes and seems to contain all necessary parameters according to the docs. The parameters also seem to be consistent with those expected in other languages/sdks.

I'm expecting $envelopeSummary (on a successful call) to include the envelopeId, status, statusDateTime, and uri which I'll then use to create the embedded signing ceremony.

I've verified that the roleName is set to 'User' on the template.

 

Here’s what I have for recipients: i.imgur.com/lCOEiNG.png

Here’s what I get from the API (from the get templates request) for the template: https://i.imgur.com/qseg6cq.png

2 replies

Userlevel 1
Badge +3

Hi, 

Welcome to the DocuSign Support Community!

As we can see, the problem you are having is that the values ​​such as name and email are not being sent correctly.

Reviewing your code I found some discrepancies with our examples of how to send an envelope with a template using PHP

This is an example of how to send a template from PHP:

Create an envelope definition from a template

public static function makeEnvelope(array $args): EnvelopeDefinition
{
# create the envelope definition with the template_id
$envelope_definition = new EnvelopeDefinition([
'status' => 'sent', 'template_id' => $args['template_id']
]);
# Create the template role elements to connect the signer and cc recipients
# to the template
$signer = new TemplateRole([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'role_name' => 'signer'
]);
# Create a cc template role.
$cc = new TemplateRole([
'email' => $args['cc_email'], 'name' => $args['cc_name'],
'role_name' => 'cc'
]);

# Add the TemplateRole objects to the envelope object
$envelope_definition->setTemplateRoles([$signer, $cc]);

return $envelope_definition;
}


Create and send the envelope

# Create the envelope request object
$envelope_definition = UseTemplateService::makeEnvelope($args["envelope_args"]);

# Call Envelopes::create API method
# Exceptions will be caught by the calling function
$envelope_api = $clientService->getEnvelopeApi();
$envelopeResponse = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);

return ['envelope_id' => $envelopeResponse->getEnvelopeId()];

You need to add the TemplateRole Object to the envelope using setTemplateRoles()

You can review our documentation and our examples at the following links:

Our SDK use Template https://github.com/docusign/code-examples-php/blob/master/src/Services/Examples/eSignature/UseTemplateService.php

 

How to request a signature by email using a template https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote/

 

Regards,


Eric | Docusign

Badge

Hi Eric,

The code I found in the examples (the same code you included) doesn’t seem to provide the array values for $args and unfortunately I can’t use it until I know those values. I’ve resorted to stack overflow - hence the discrepancies. However now I’ve gotten a little further and I’m able to generate the envelope ID successfully, so it seems that my code and the example code are a means to the same end.

$apiClient = new ApiClient($config);

// Step 2: Create an Envelope from a template
$templateId = env('TEMPLATE_ID');
$accountId = env('API_ACCOUNT_ID');
$envelopeApi = new EnvelopesApi($apiClient);
$templateRole = new TemplateRole([
'email' => 'email@example.com', // recipient's email
// 'clientUserId' => '12345',
'name' => 'JohnDoe', // recipient's name
'roleName' => 'User', // The role name as defined in the template
]);

$envelopeDefinition = new EnvelopeDefinition([
'status' => 'created',
'templateId' => $templateId,
'templateRoles' => [$templateRole]
]);
$envelopeSummary = $envelopeApi->createEnvelope($accountId, $envelopeDefinition);
$envelopeId = $envelopeSummary->getEnvelopeId();


// Step 3: Generate a signing URL
$recipientViewRequest = new RecipientViewRequest([
'authenticationMethod' => 'None', // Should be set based on your app's auth method
// 'userId' => '12345', // Same clientUserId set in TemplateRole
'recipientId' => '1', // Typically '1' unless you have multiple recipients
'returnUrl' => 'https://yourapp.com/docusign-return', // URL to which the user is redirected after signing
'email' => 'email@example.com',
'userName' => 'JohnDoe',
]);

// Generate the recipient view URL
$recipientView = $envelopeApi->createRecipientView($accountId, $envelopeId, $recipientViewRequest);

 

My next question is about creating the recipient view definition after the envelope is created which is step 4 here. I’m getting
 

Error while requesting server, received a non successful HTTP code [400] with response Body: O:8:"stdClass":2:{s:9:"errorCode";s:25:"INVALID_REQUEST_PARAMETER";s:7:"message";s:101:"The request contained at least one invalid parameter. A value was not found for parameter 'userName'.";}

despite the fact that userName is in the parameters.

Reply