docusignapidocusigncompositetmplts

JSON Docusign Inline mulitpule Documents


I have my Json working for single document and transforms the PDF fields, but when I try to add second document. I Get JSON Parse error.

This works

"document": {
"documentId": "1",
"name": "Test Contract With Fields.pdf",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
    }

this also works but doesn't transforms the PDFFields.

 "inlineTemplates": [
        {
          "documents": [
            {
              "documentBase64": "<Base64BytesHere>",
              "documentId": "1",
              "name": "test",
              "transformPdfFields": "true"
            },
            {
              "documentBase64": "<Base64BytesHere>",
              "documentId": "2",
              "name": "test 2",
              "order": "2"
            }
          ],

Adding Square [] and second document breaks. Tried making Documents

    "document": [{
        "documentId": "1",
        "name": "Test Contract With Fields.pdf",
        "transformPdfFields": "true",
        "documentBase64": "'.$documentHashpdf.'"
    },
    {

        "documentId": "2",
        "name": "Test Contract With Fields 2.pdf",
        "transformPdfFields": "true",
        "documentBase64": "'.$documentHashpdf.'"

    }]

**Update: Complete JSON Looking to add a second **document****

{
    "emailBlurb": "Test Blurb",
    "emailSubject": "Test subject",
    "status": "sent",
    "compositeTemplates": [
        {
            "compositeTemplateId": "1",
            "inlineTemplates": [
                {
                    "sequence": "1","documents": [
              {
                "documentBase64": "'.$documentHashpdf.'",
"documentId": "2",
              "name": "Not working", "order": "2"
            }
          ],

                    "recipients": {
                        "signers": [
                            {
                                "email": "*******",
                                "name": "********e",
                                "recipientId": "1",
                                "smsAuthentication": {
                                "senderProvidedNumbers": ["******"]
                                },
                                "idCheckConfigurationName": "SMS Auth $",
                                "requireIdLookup": "true",
                                "clientUserId": "1001",
                                "defaultRecipient": "true",
                                "tabs": {
                                    "signHereTabs": [
                                        {
                                            "pageNumber": "1",
                                            "documentId": "1",
                                            "tabLabel": "text 1",
                                            "recipientId": "1"
                                        }
                                    ],
                                    "fullNameTabs": [
                                        {
                                            "pageNumber": "1",
                                            "documentId": "1",
                                            "xPosition": "20",
                                            "yPosition": "20",
                                            "height": "10",
                                            "width": "20",
                                            "tabLabel": "Text 2",
                                            "recipientId": "1"
                                        }
                                    ],
                                    "dateSignedTabs": [
                                        {
                                            "pageNumber": "1",
                                            "documentId": "1",
                                            "xPosition": "20",
                                            "yPosition": "30",
                                            "height": "10",
                                            "width": "20",
                                            "tabLabel": "text 3",
                                            "recipientId": "1"
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ],
            "document": {
                "documentId": "1",
                "name": "Working",
                "transformPdfFields": "true",
                "documentBase64": "'.$documentHashpdf.'"
            }       }
    ]

Solution

  • There are 3 "models" for constructing envelopes. I recommend using composite templates in the intended way, where you manage each document contribution to the envelope by enclosing within separate compositeTemplate elements. I reworked your JSON like this:

    {
      "emailBlurb": "Test Blurb",
      "emailSubject": "Test subject",
      "status": "sent",
      "compositeTemplates": [{
          "compositeTemplateId": "1",
          "document": {
            "documentId": "1",
            "name": "Working",
            "transformPdfFields": "true",
            "documentBase64": "'.$documentHashpdf.'"
          },
          "inlineTemplates": [{
            "sequence": "1",
            "recipients": {
              "signers": [{
                "email": "*******",
                "name": "********e",
                "recipientId": "1",
                "smsAuthentication": {
                  "senderProvidedNumbers": ["******"]
                },
                "idCheckConfigurationName": "SMS Auth $",
                "requireIdLookup": "true",
                "clientUserId": "1001",
                "defaultRecipient": "true"
              }]
            }
          }]
        },
        {
          "compositeTemplateId": "2",
          "document": {
            "documentBase64": "'.$documentHashpdf.'",
            "documentId": "2",
            "name": "Not working",
            "transformPdfFields": "true"
          },
          "inlineTemplates": [{
            "sequence": "1",
            "recipients": {
              "signers": [{
                "email": "*******",
                "name": "********e",
                "recipientId": "1",
                "smsAuthentication": {
                  "senderProvidedNumbers": ["******"]
                },
                "idCheckConfigurationName": "SMS Auth $",
                "requireIdLookup": "true",
                "clientUserId": "1001",
                "defaultRecipient": "true"
              }]
            }
          }]
        }
      ]
    }
    

    In this fashion, any number of additional documents you wish to add would simply be another compositeTemplate element added to the array. This works for additional documents regardless of whether you wish to transform PDF fields, documents sourced from DocuSign templates, or any additional document for which you want to apply a template to overlay.

    Note that the use of compositeTemplateId is only needed to relate multipart form attachments, which is a cleaner way to handle your documents rather than base64 encoding them in documentBase64 elements.