2

I'm trying to send an envelope in DocuSign using REST API. For adding the document to envelopes I'm using multipart/form-data POST method. I tried sending this request using POSTMAN but I'm getting a below response:

{
    "errorCode": "INVALID_CONTENT_TYPE",
    "message": "Content Type specified is not supported. Content-Type for part[0] must be application/json or application/xml"
}

This is my POSTMAN request:

POST /restapi/v2/accounts/****/envelopes HTTP/1.1
Host: demo.docusign.net
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Authorization: Bearer *********
Cache-Control: no-cache
Postman-Token: c0b940e1-4b6c-4848-abd1-ed5c9c712cb5

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=""

{
  "status": "sent",
  "emailSubject": "Example of one recipient, type signer",
  "documents": [{
    "documentId": "1",
    "name": "contract.pdf",
  }],
  "recipients": {
    "signers": [{
      "name": "Lisa Simpson",
      "email": "lisa@email.com",
      "recipientId": "1",
      "routingOrder": "1",
      "tabs": {
        "signHereTabs": [{
          "xPosition": "150",
          "yPosition": "200",
          "documentId": "1",
          "pageNumber": "1"
        }],
      }
    }]
  }
}
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="Test.pdf"
Content-Type: application/pdf


------WebKitFormBoundary7MA4YWxkTrZu0gW--

My questions are:

  1. Is there a way in POSTMAN to specify the Content-Type for part[0]?
  2. What should be the key names for part[0] & part[1]?
  3. How to pass documentid in part[1]?

I'm referring: https://docs.docusign.com/esign/restapi/Envelopes/Envelopes/create/#examples REST API documentation

Roshan007
  • 658
  • 2
  • 7
  • 15

1 Answers1

1

See below for a proper self-contained working DocuSign envelope using multi-part form vs multipart/form-data -

DocuSign Support Case 04093516 is closed and a Jira ticket was filed for the erroneous mention of form-data in the documentation about sending envelopes via REST API.

Hard returns and spacing are critical. Also, recommend you update email addresses to your test Gmail account, notice the same account with + can be used. If using Postman make sure you are using "RAW" not form-data, x-www-form-urlencoded or binary. See image below:

enter image description here

Link here as well - https://blog.grigsbyconsultingllc.com/wp-content/uploads/Screenshot-2018-04-18-07.26.26.png

You still need headers, specifically content-type and authentication type aka : -H 'content-type: multipart/form-data; boundary=AAA' \ -H 'x-docusign-authentication; See Stack Overflow link How should the header X-DocuSign-Authentication be used for REST and SOAP?

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

{
"emailBlurb": "Test for CEFTAF Lab 2 Custom Fields Recipient Fields Document Fields",
"emailSubject": "Test for Dev 201 Lab 2",
"status": "created",
               "notification":{
              "useAccountDefaults":"false",
              "reminders":{
                 "reminderEnabled":"true",
                 "reminderDelay":"2",
                 "reminderFrequency":"2"
              },
              "expirations":{
                 "expireEnabled":"true",
                 "expireAfter":"15",
                 "expireWarn":"1"
              }
              }, 
"compositeTemplates": [{
"inlineTemplates": [{
"sequence": "1",
"customFields": {
    "textCustomFields": [
      {
        "fieldId": "123",
        "name": "MYCustomID",
        "show": "false",
        "required": "false",
        "value": "myId012345"
      }
    ],
    "listCustomFields": [
      {
        "listItems": [
          "elementValue1","elementValue2","elementValue3"
        ],
        "fieldId": "1234",
        "name": "myArrayListofItems",
        "show": "false",
        "required": "false",
        "value": "3"
      }
    ]
  },

"documents": [{
"documentId": "1",
"name": "test1.txt",
      "documentFields": [
        {
          "name": "Test1",
          "value": "value for test1"
        }
      ],
},
            {
"documentId": "2",
"name": "test2.txt"
},
            {
"documentId": "3",
"name": "test3.txt"
}

            ],
"recipients": {
            "carbonCopies": [
                            {
                                "email": "dsproservedemosoapui+Testcc@gmail.com",
                                "name": "David Grigsby (see all document)",
                                "recipientId": "3",
                                "routingOrder": "3"
                            },
                            {
                                "email": "dsproservedemosoapui+Testcc1@gmail.com",
                                "name": "David Grigsby (see all)",
                                "recipientId": "4",
                                "routingOrder": "4"
                            }
                            ],
"signers": [{
"recipientId": "1",
"customFields": [
  "Recip 1 ID 1234"
],
"name": "David Grigsby (Sees all)",
"email": "dsproservedemosoapui+Test1@gmail.com", 
                    "routingOrder": "1",
                    "tabs": {
                    "signHereTabs": [{
                      "anchorString": "Sign1",
                      "tabLabel": "Sign Here 1"
                      }]
                    }
},
                {
"recipientId": "2",
"name": "David Grigsby (sees all )",
"email": "david.grigsby@yahoo.com", 
                    "routingOrder": "2",
                    "tabs": {
                    "signHereTabs": [{
                      "anchorString": "Sign2",
                      "tabLabel": "Sign Here 2"
                      }]
                    }
}
                ]
}
}]
}]
}

--AAA
Content-Type: application/txt
Content-Disposition: file; filename="test1.txt"; documentid=1

Test Document 1 

Sign1 Here _______________________________    Custom1 Approve:



Sign2 Here _______________________________    Custom2 Approve:


--AAA
Content-Type: application/txt
Content-Disposition: file; filename="test2.txt"; documentid=2

Test Document 2

Sign1 Here _______________________________

--AAA
Content-Type: application/txt
Content-Disposition: file; filename="test3.txt"; documentid=3

Test Document 3

No Tabs for anyone means visbile to all by default unless excluded

--AAA--

And the difference for a PDF is below, recommend using Base64

--AAA
Content-Type: application/pdf
Content-Disposition: file; filename="f4506t.pdf"; documentid=1
Content-Transfer-Encoding: base64

JVBERi0xLjcNJeLjz9MNCjMwMSAwIG9iag08PC9MaW5lYXJpemVkIDEvTCA3NDAzMi9PIDMwMy9F
IDMzNjI2L04gMi9UIDczNjM4L0ggWyA2MzAgMjk2XT4+DWVuZG9iag0gICAgICAgICAgICAgICAg

.... pdf body bulk removed ......

o4IlmH0CxPYUYWBiYGBUB5PVDADOVQiaCmVuZHN0cmVhbQplbmRvYmoKc3RhcnR4cmVmCjg1MDUz
CiUlRU9GCg==
--AAA--

Image of Note from DocuSign Case: enter image description here

David W Grigsby
  • 1,554
  • 1
  • 13
  • 23
  • Thanks but my questions are: 1. Is there a way in POSTMAN to specify the Content-Type for part[0]? 2. What should be the key names for part[0] & part[1]? 3. How to pass documentid in part[1] along with the document in POSTMAN? – Roshan007 Apr 14 '18 at 02:38
  • @Roshan007 - 1. Yes, the sample shows that both the "Postman" header section and in each part you specify any "header" you need, see the pdf sample at the bottom. This example was taken from Postman. 2. Your first portion aka Part 0 is always the envelope and Json or XML. 3. I show the Document ID in both the text type and the pdf type. – David W Grigsby Apr 14 '18 at 10:41
  • @Roshan007 Also, you should be able to cut and paste the above sample and use your bear token to issue the call to see it work. Also, please note the sample is longer than the "code segment box" so you will need to scroll down once you have it selected. – David W Grigsby Apr 14 '18 at 10:47
  • I'm using Postman v6.0.10 and for form-data I have the option of specifying Text or File for each key-value pair but I cant see an option to specify the content-type (application/json) for part[0]. – Roshan007 Apr 18 '18 at 07:09
  • @Roshan007 - I have added a photo to assist you - Select "RAW" vs form-data. – David W Grigsby Apr 18 '18 at 11:33
  • @Roshan007 I look forward to your update on this question and answer, please take the time in the community to come back to your questions and update them, so far I don't see that you have done that on the 8 questions you have submitted to date. – David W Grigsby Apr 21 '18 at 17:19
  • @Roshan007 FYI - I have created a support case to correct documentation on this point. – David W Grigsby Apr 21 '18 at 17:39
  • @Roshan007 DocuSign Case 04093516 is closed and a Jira ticket was filed for the erroneous mention of form-data in the documentation about sending envelopes. – David W Grigsby Apr 25 '18 at 14:45
  • Thank you for the example request. I'm having trouble finding the DocuSign documentation for this procedure. Can you give a reference for where base64 encoding of pdfs is recommended? – ldanilek Sep 22 '18 at 02:15
  • See https://developers.docusign.com/esign-rest-api/guides/requests-and-responses Multipart Form Requests There are generally two ways to upload documents for these methods: base64 encoding the document and inserting the encoded bytes in the appropriate field. In the Envelopes: create method this is the documentBase64 field. – David W Grigsby Sep 23 '18 at 12:45