简体   繁体   中英

Docusign REST API does not recognize document in base64

We are trying to use Docusign's REST API to post a template along side with a pdf document using the documentBase64 property, however, it does not seem to recognize the document.

Here are the parameters we used, data is created by fs.readFile :

params = 
    emailSubject: 'Sample Document'
    envelopeTemplateDefinition:
      name: 'Template 1'
    documents: [
      name: 'Document 1'
      documentId: 1
      documentBase64: data.toString('base64')
    ]
    recipients:
      signers: [
        recipientId: 1
        roleName: "Signer 1"
      ,
        recipientId: 2
        roleName: "Signer 2"
      ,
        recipientId: 3
        roleName: "Signer 3"
      ,
        recipientId: 4
        roleName: "Signer 4"
      ,
        recipientId: 0
        roleName: "Signer 0"
      ]

We are using node's request library to send the POST request, the auth header is properly set, and the API does return a response saying that the template is successfully created, however, when we check it in the Docusign console, it shows that the template does not contain any document.

We used similar method to create a draft envelope and everything works fine - the attached pdf document is recognized - so we assume it should work for the template as well, but it doesn't.

I am very confused by the inconsistent behavior between the two endpoints, so does the post template endpoint does not support documentBase64? Do I have to use a multipart/form-data request?

Also, we are using the sandbox account to test, does this incur any restrictions?

Any help is appreciated.

The "Create Template" operation does not currently support the documentBase64 property -- when creating a Template with the API, the request must instead be a multi-part request (where the first part contains the JSON request body and each subsequent part after the first part represent's a document's contents).

From the DocuSign REST API Guide ( https://10226ec94e53f4ca538f-0035e62ac0d194a46695a3b225d72cc8.ssl.cf2.rackcdn.com/rest-api-guide-v2.pdf ), the definition of the POST Template operation on p197 (POST /accounts/{accountId}/templates) is:

Saves a template definition using a multipart request.

If you search the guide for "documentBase64" you'll see that it is only mentioned in the context of creating/sending Envelopes (and not in the context of creating Templates, unfortunately). The "documentBase64" property was a fairly recent addition to the "Create Envelope" operation, so perhaps (hopefully) DocuSign will add support for it in the "Create Template" operation soon.

Here's an example multipart request body that specifies 2 documents and uses AAA as the Boundary:

POST https://demo.docusign.net/restapi/v2/accounts/295724/envelopes
X-DocuSign-Authentication: {"Username":"email","Password":"password","IntegratorKey":"key"}
Content-Type: multipart/form-data; boundary=AAA
Accept: application/json
Host: demo.docusign.net
Content-Length: 31476
Expect: 100-continue

--AAA
Content-Type: application/json
Content-Disposition: form-data

JSON_REQUEST_BODY_HERE
--AAA
Content-Type:application/pdf
Content-Disposition: file; filename="ABC.pdf"; documentid=1 

UNENCODED_DOCUMENT_1_BYTES_HERE
--AAA
Content-Type:application/pdf
Content-Disposition: file; filename="DEF.pdf"; documentid=2 

UNENCODED_DOCUMENT_2_BYTES_HERE
--AAA--

When creating your multipart request, keep in mind that line breaks are important (must be structured as shown above) and the document bytes must be not be encoded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM