Docusign - 发送信封REST API(POST multipart / form-data)

时间:2018-04-13 12:18:00

标签: rest post multipartform-data docusignapi

我正在尝试使用REST API在DocuSign中发送信封。为了将文档添加到信封,我正在使用multipart / form-data POST方法。 我尝试使用POSTMAN发送此请求,但我收到以下回复:

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

这是我的POSTMAN请求:

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--

我的问题是:

  1. POSTMAN中有没有办法为part [0]指定Content-Type?
  2. 部分[0]&的关键名称应该是什么?第1部分]?
  3. 如何在第[1]部分中传递documentid?
  4. 我指的是:https://docs.docusign.com/esign/restapi/Envelopes/Envelopes/create/#examples REST API文档

1 个答案:

答案 0 :(得分:1)

使用多部分表格 multipart / form-data -

DocuSign支持案例04093516 已关闭,并且在有关通过REST API发送信封的文档中错误提及表单数据的情况下提交了Jira票证。

硬回车和间距至关重要。此外,建议您更新测试Gmail帐户的电子邮件地址,注意使用+的同一帐户。 如果使用Postman确保您使用" RAW"不是form-data,x-www-form-urlencoded或binary。见下图:

enter image description here

此处也链接 - https://blog.grigsbyconsultingllc.com/wp-content/uploads/Screenshot-2018-04-18-07.26.26.png

你仍然需要标题,特别是内容类型和身份验证类型aka:   -H' content-type:multipart / form-data;边界= AAA' \   -H' x-docusign-authentication;请参阅堆栈溢出链接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--

下面是PDF的差异,建议使用Base64

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

JVBERi0xLjcNJeLjz9MNCjMwMSAwIG9iag08PC9MaW5lYXJpemVkIDEvTCA3NDAzMi9PIDMwMy9F
IDMzNjI2L04gMi9UIDczNjM4L0ggWyA2MzAgMjk2XT4+DWVuZG9iag0gICAgICAgICAgICAgICAg

.... pdf正文批量删除......

o4IlmH0CxPYUYWBiYGBUB5PVDADOVQiaCmVuZHN0cmVhbQplbmRvYmoKc3RhcnR4cmVmCjg1MDUz
CiUlRU9GCg==
--AAA--

DocuSign案例中的注释图片: enter image description here

相关问题