DocuSign API与ColdFusion [英] DocuSign API with ColdFusion

查看:474
本文介绍了DocuSign API与ColdFusion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新了解决方案

我正在尝试使用ColdFusion集成DocuSign API,并且遇到问题。我可以成功地进行身份验证并检索基本URL。但是,当试图用一个收件人和文档创建信封时,我得到一个错误,说明边界终止符没有在请求中找到(当显然是)。

I'm trying to integrate the DocuSign API using ColdFusion and keep running into an issue. I am able to authenticate successfully and retrieve the base URL. However, when trying to create the envelope with a single recipient and document, I get an error stating that the "boundary terminator" is not found in the request (when it clearly is).

我知道这个问题类似于这里的另一篇文章,但是那是从一段时间以前,并且从来没有完全回答。

I know this questions is similar to another post here but that was from a while ago and was never completely answered.

我第一次阅读PDF文档:

I first read in the PDF document:

<cffile action="READBINARY" file="Agreement.pdf" variable="docData">
<cfset docData = BinaryEncode(docData,"Base64")>

然后,我使用元素在XML中创建包络定义,以包含编码的二进制PDF数据:

I then create the envelope definition in XML using the element to include the encoded binary PDF data:

<cfset envelope = "<envelopeDefinition xmlns=""http://www.docusign.com/restapi"">
                <status>Sent</status>
                <emailSubject>eSignature request</emailSubject>
                <emailBlurb>Please sign the document</emailBlurb>
                <recipients>
                    <signers>
                        <signer>
                            <recipientId>1</recipientId>
                            <name>eCS Buyer</name>
                            <email>XXX@XXXX.com</email>
                            <tabs>
                                <signHereTabs>
                                    <signHere>
                                        <documentId>1</documentId>
                                        <pageNumber>3</pageNumber>
                                        <xPosition>10</xPosition>
                                        <yPosition>100</yPosition>
                                    </signHere>
                                </signHereTabs>
                            </tabs>
                        </signer>
                    </signers>
                </recipients>
                <documents>
                    <document>
                        <name>Agreement.pdf</name>
                        <documentId>1</documentId>
                        <fileExtension>pdf</fileExtension>
                        <documentBase64>#docData#</documentBase64>
                    </document>
                </documents>
               </envelopeDefinition>">

最后,我POST的信息: p>

Lastly, I POST the information:

<cfhttp url="#baseURL#/envelopes" method="POST" resolveurl="Yes" throwonerror="No">
<cfhttpparam name="X-DocuSign-Authentication" type="HEADER" value="<DocuSignCredentials><Username>#userName#</Username><Password>#password#</Password><IntegratorKey>#integratorKey#</IntegratorKey></DocuSignCredentials>">
<cfhttpparam name="Content-Type" type="HEADER" value="application/xml">
<cfhttpparam name="Accept" type="HEADER" value="application/xml">
<cfhttpparam name="Content-Length" type="HEADER" value="#Len(envelope)#">
<cfhttpparam name="request_body" type="BODY" value="#envelope#">
</cfhttp>

我试图将请求主体的TYPE属性更改为XML和FORMFIELD,但仍然不工作,我甚至尝试更改信封到JSON格式无效。

I tried changing the TYPE attribute for the request body to XML and FORMFIELD but is still doesn't work. I even tried changing the envelope to JSON format to no avail.

生成的错误是:

<errorCode>INVALID_REQUEST_BODY</errorCode><message>The request body is missing or improperly formatted. The XML request does not match the expected format. </message></errorDetails> 

我一直在努力工作数周。非常感谢任何指导。

I have been struggling with this for weeks. Any guidance would be GREATLY appreciated.

推荐答案

很可能是额外CRLF的问题(即额外的换行符)。请参阅此其他论坛帖子中的答案,了解完整请求结构应该是什么样子的示例: Docusign:无法从restapi v2中的文档创建信封

Most likely an issue with extra CRLF (i.e., extra line breaks). See the answer in this other forum post for an example of what the full request structure should look like: Docusign : Unable to create envelope from document in restapi v2.

UPDATE#1

看起来您的XML请求正文缺少有关文档的信息。尝试添加文档元素作为 envelopeDefinition 的子元素(即作为收件人的对等元素):

Looks like your XML request body is missing information about the Document. Try adding a documents element as a child element of envelopeDefinition (i.e., as a peer element to recipients):

<envelopeDefinition xmlns=""http://www.docusign.com/restapi"">
    ...            
    <documents>
        <document>
            <name>Agreement.pdf</name>
            <documentId>1</documentId>
        </document>
    </documents>
    ...
</envelopeDefinition>

此外,请确保在请求的后续部分中发送的文档字节不会被编码。

Also, make sure the document bytes that your sending in the subsequent part of the request are not encoded.

UPDATE#2

我不太了解ColdFusion,这行代码使你看起来像是你对包含在请求中的字节流进行编码(base64):

I don't know much about ColdFusion, but this line of your code makes it look like you're (base64) encoding the byte stream that you're including in the Request:

<cfset docData = BinaryEncode(docData,"Base64")>

这可能会导致您的最新问题,因为我不认为DocuSign会接受编码的字节流

This could be causing your latest issue, as I don't believe DocuSign will accept an encoded byte stream when it's included in the manner you're currently utilizing.

如果您必须base64编码字节流,您可以添加 documentBase64 属性在文档元素下,以包含base64编码的字节流。 (请参阅DocuSign REST API指南第104页 - http://www.docusign .com / sites / default / files / REST_API_Guide_v2.pdf 。)如果您使用此方法,您的请求将不再需要是multipart请求,因为文档字节将包含在XML部分请求正文(不在后续/单独的部分)。下面是一个示例,如果base64编码的字节流包含在 documentBase64 元素中,请求会是什么样子:

If you must base64-encode the byte stream, you could add a documentBase64 property under the document element to contain the base64-encoded byte stream. (See page 104 of the DocuSign REST API Guide -- http://www.docusign.com/sites/default/files/REST_API_Guide_v2.pdf.) If you utilized this approach, your request would no longer need to be a 'multipart' request, since the document bytes would be included in the XML portion of the Request Body (not in a subsequent/separate part). Here's an example of what the Request would look like, if the base64-encoded byte stream was included within the documentBase64 element:

POST /restapi/v2/accounts/ACCOUNT_NUMBER/envelopes HTTP/1.1
Host: demo.docusign.net
X-DocuSign-Authentication: {"Username":"SENDER_EMAIL_ADDRESS","Password":"PASSWORD","IntegratorKey":"INT_KEY"}
Content-Type: application/xml

<envelopeDefinition xmlns="http://www.docusign.com/restapi">
    <accountId>ACCOUNT_ID</accountId>
    <status>sent</status>  
    <emailSubject>eSignature request</emailSubject>
    <emailBlurb>Please sign the document</emailBlurb>
    <recipients>
      <signers>
        <signer>
         <email>johnsEmail@outlook.com</email>
         <name>John Doe</name>
         <recipientId>1</recipientId>
         <routingOrder>1</routingOrder>  
         <tabs>
            <signHereTabs>
                <signHere>
                    <documentId>1</documentId>
                    <pageNumber>1</pageNumber>
                    <xPosition>10</xPosition>
                    <yPosition>100</yPosition>
                </signHere>
            </signHereTabs>
        </tabs>
        </signer>
      </signers>
    </recipients>
    <documents>
        <document>
            <name>Agreement.pdf</name>
            <documentId>1</documentId>
            <fileExtension>pdf</fileExtension>
            <documentBase64>BASE64-ENCODED-BYTE-STREAM</documentBase64>
        </document>
    </documents>
</envelopeDefinition>

由于文档字节包含在请求的XML部分中,因此请求不再需要多部分 - 只需传递XML请求正文,如上所示,就是这样。

Since the document bytes are included within the XML portion of the request, the request no longer needs to be multi-part -- simply pass the XML Request body as I've shown above, and that's it.

这篇关于DocuSign API与ColdFusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆