php - Docusign Composite Template

We are working with docusign Composite Template API with PHP. We Tried to add a custom document with base64 encoded format with signHereTabs object with values. We are able to create envelope and views for recipient successfully.But the issue is it's not generating signHereTabs which we are tried for recipient. Can you please help us to resolve this issue? Sample Request in json to create envelope:

{
  "status": "sent",
  "compositeTemplates": [
    {
      "compositeTemplateId": "1",
      "inlineTemplates": [
        {
          "sequence": "1",
          "recipients": {
            "signers": [
              {
                "clientUserId": "1000",
                "name": "Full Name",
                "email": "my email",
                "recipientId": "1",
                "roleName": "Sender",
                "tabs": {
                  "signHereTabs": [
                    {
                      "anchorString": "\/sig1\/",
                      "anchorUnits": "pixels",
                      "anchorXOffset": "20",
                      "anchorYOffset": "10"
                    }
                  ]
                }
              }
            ]
          },
          "customFields": {
            "textCustomFields": [
              {
                "name": "MyOwnField",
                "required": "true",
                "show": "true",
                "value": "MyValue"
              }
            ]
          }
        }
      ],
      "document": {
        "documentBase64": "<base64 encoded string>",
        "documentId": "1",
        "fileExtension": "pdf",
        "name": "Agreement.pdf",
        "transformPdfFields": false
      }
    }
  ]
}

View Recipient sample request:

{
  "document": {
    "documentBase64": "<base64 encoded string>",
    "documentId": "1",
    "fileExtension": "pdf",
    "name": "Agreement.pdf",
    "transformPdfFields": false
  }
}

Answer

Solution:

The fields (tabs) need to be a part of the signers object.

Here's a working example from the API Request Builder:

{
    "emailSubject": "Please sign the attached document",
    "status": "sent",
    "compositeTemplates": [
      {
        "compositeTemplateId": "1",
        "document": {
          "filename": "anchorfields.pdf",
          "name": "Example document",
          "fileExtension": "pdf",
          "documentId": "1"
        },
        "inlineTemplates": [
          {
            "sequence": "1",
            "recipients": {
              "signers": [
                {
                  "email": "signer_email@example.com",
                  "name": "Signer's name",
                  "recipientId": "1",
                  "clientUserId": "1000",
                  "tabs": {
                    "signHereTabs": [
                      {
                        "anchorString": "/sig1/",
                        "anchorXOffset": "20",
                        "anchorUnits": "pixels"
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  }

Here it is with the PHP SDK (auto-generated by the API Request Builder):

<?php # DocuSign Builder example. Generated: Sat, 03 Sep 2022 18:34:12 GMT
      # DocuSign ?�? 2022. MIT License -- https://opensource.org/licenses/MIT
      # @see <a href="https://developers.docusign.com">DocuSign Developer Center</a>
require_once ('vendor/autoload.php');
require_once ('vendor/docusign/esign-client/autoload.php');
# Note: the access_token is for testing and is temporary. It is only good for 8 hours from the time you 
#       authenticated with API Request Builder. 
const base_uri = 'https://demo.docusign.net/';
const access_token = '';
const account_id = '';
const document_directory = '.'; # The directory with your documents, relative to this script's directory
#
function sendDocuSignEnvelope() {
    $docs_path = getcwd() . '/' . document_directory . '/';
    $document1 = new \DocuSign\eSign\Model\Document([
        'document_id' => "1",  
        'file_extension' => "pdf",  
        'document_base64' => base64_encode(file_get_contents($docs_path.'anchorfields.pdf')),  # filename is anchorfields.pdf
        'name' => "Example document" 
        ]);
    $sign_here_tab1 = new \DocuSign\eSign\Model\SignHere([
        'anchor_string' => "/sig1/",  
        'anchor_units' => "pixels",  
        'anchor_x_offset' => "20" 
        ]);
    $sign_here_tabs1 = [$sign_here_tab1];
    $tabs1 = new \DocuSign\eSign\Model\Tabs([
        'sign_here_tabs' => $sign_here_tabs1 
        ]);
    $signer1 = new \DocuSign\eSign\Model\Signer([
        'client_user_id' => "1000",  
        'email' => "signer_email@example.com",  
        'name' => "Signer's name",  
        'recipient_id' => "1",  
        'tabs' => $tabs1 
        ]);
    $signers1 = [$signer1];
    $recipients1 = new \DocuSign\eSign\Model\Recipients([
        'signers' => $signers1 
        ]);
    $inline_template1 = new \DocuSign\eSign\Model\InlineTemplate([
        'recipients' => $recipients1,  
        'sequence' => "1" 
        ]);
    $inline_templates1 = [$inline_template1];
    $composite_template1 = new \DocuSign\eSign\Model\CompositeTemplate([
        'composite_template_id' => "1",  
        'document' => $document1,  
        'inline_templates' => $inline_templates1 
        ]);
    $composite_templates1 = [$composite_template1];
    $envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
        'composite_templates' => $composite_templates1,  
        'email_subject' => "Please sign the attached document",  
        'status' => "sent" 
        ]);

    try {
        $config = new \DocuSign\eSign\Configuration();
        $config->setHost(base_uri . 'restapi');
        $config->addDefaultHeader('Authorization', 'Bearer ' . access_token);
        $api_client = new \DocuSign\eSign\Client\ApiClient($config);
        $envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
        $result = $envelope_api->createEnvelope(account_id, $envelope_definition);
        $envelope_id = $result->getEnvelopeId();
        printf("\nEnvelope status: %s. Envelope ID: %s\n", $result->getStatus(), $result->getEnvelopeId());
        return $envelope_id;
    } catch (Exception $e) {
        printf ("\n\nException from createEnvelope!\n%s", $e->getMessage());
        if ($e instanceof DocuSign\eSign\Client\ApiException) {
            printf ("\nAPI error information: \n%s", $e->getResponseBody());
        }
        return FALSE;
    }
}

function recipientView ($envelope_id) {
    $recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest([
        'authentication_method' => "None",  
        'client_user_id' => "1000",  
        'email' => "signer_email@example.com",  
        'return_url' => "https://docusign.com",  
        'user_name' => "Signer's name" 
        ]);
    if (!$recipient_view_request || !$envelope_id) {return;}

    try {
        $config = new \DocuSign\eSign\Configuration();
        $config->setHost(base_uri . 'restapi');
        $config->addDefaultHeader('Authorization', 'Bearer ' . access_token);
        $api_client = new \DocuSign\eSign\Client\ApiClient($config);
        $envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
        $result = $envelope_api->createRecipientView(account_id, $envelope_id,
            $recipient_view_request);
        print ("\nCreate recipient view succeeded.");
        printf ("Open the signing ceremony's long URL within 5 minutes: \n%s\n\n", $result->getUrl());
    } catch (Exception $e) {
        printf ("\n\nException from createRecipientView!\n%s", $e->getMessage());
        if ($e instanceof DocuSign\eSign\Client\ApiException) {
            printf ("\nAPI error information: \n%s", $e->getResponseBody());
        }
    }
}

# The mainline
$envelope_id = sendDocuSignEnvelope();
recipientView($envelope_id);
print("Done.\n");

Source