无法发送附件 - Salesforce Docusign API

时间:2016-12-02 14:28:37

标签: salesforce docusignapi apex

我试图通过Apex和Docusign“CreateAndSendEnvelope”API在机会记录中发送附件(记录有一个附件)。

但我收到此错误“ DocuSign EnvelopeId:Exception - System.CalloutException:Web服务标注失败:WebService返回SOAP错误:锚标记处理期间发生错误。无效文档faultcode = soap:Client faultactor = https://demo.docusign.net/api/3.0/dsapi.asmx

以下是使用的代码。

 // Render the contract
        System.debug('Rendering the contract');
        PageReference pageRef = new PageReference('/apex/RenderContract');
        pageRef.getParameters().put('id',contract.Id);

        //Blob pdfBlob = pageRef.getContent();     
        Attachment att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE Parentid = :contract.Id LIMIT 1];
        Blob pdfBlob = att.Body; 


        // Document
        DocuSignAPI.Document document = new DocuSignAPI.Document();
        document.ID = 1;
        document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
        document.Name = 'Contract';
        document.FileExtension = 'pdf';
        envelope.Documents = new DocuSignAPI.ArrayOfDocument();
        envelope.Documents.Document = new DocuSignAPI.Document[1];
        envelope.Documents.Document[0] = document;

        // Recipient
        System.debug('getting the contact');
        Contact contact = [SELECT email, FirstName, LastName 
            from Contact where id = :contract.CustomerSignedId];

        DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
        recipient.ID = 1;
        recipient.Type_x = 'Signer';
        recipient.RoutingOrder = 1;
        recipient.Email = contact.Email;
        recipient.UserName = contact.FirstName + ' ' + contact.LastName;

        // This setting seems required or you see the error:
        // "The string '' is not a valid Boolean value. 
        // at System.Xml.XmlConvert.ToBoolean(String s)" 
        recipient.RequireIDLookup = false;      

        envelope.Recipients = new DocuSignAPI.ArrayOfRecipient();
        envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
        envelope.Recipients.Recipient[0] = recipient;

        // Tab
        DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab();
        tab1.Type_x = 'SignHere';
        tab1.RecipientID = 1;
        tab1.DocumentID = 1;
        tab1.AnchorTabItem = new DocuSignAPI.AnchorTab();
        tab1.AnchorTabItem.AnchorTabString = 'By:';


        DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab();
        tab2.Type_x = 'DateSigned';
        tab2.RecipientID = 1;
        tab2.DocumentID = 1;
        tab2.AnchorTabItem = new DocuSignAPI.AnchorTab();
        tab2.AnchorTabItem.AnchorTabString = 'Date Signed:';

        envelope.Tabs = new DocuSignAPI.ArrayOfTab();
        envelope.Tabs.Tab = new DocuSignAPI.Tab[2];
        envelope.Tabs.Tab[0] = tab1;        
        envelope.Tabs.Tab[1] = tab2;        

        System.debug('Calling the API');
        try {
            DocuSignAPI.EnvelopeStatus es 
            = dsApiSend.CreateAndSendEnvelope(envelope);
            envelopeId = es.EnvelopeID;
        } catch ( CalloutException e) {
            System.debug('Exception - ' + e );
            envelopeId = 'Exception - ' + e;
        }

任何想法如何克服这个错误?

感谢。

2 个答案:

答案 0 :(得分:0)

原创海报(OP' s)的评论是

  

它可以将整个记录渲染为pdf ...但是现在我只尝试发送附件而不是整个记录..我开始得到这个错误。

所以我的猜测是信封请求有文档问题。

调试的最佳方式:查看发送到DocuSign平台的内容。

尝试docsbeta API logger。然后通过编辑问题将日志添加到您的问题中。

答案 1 :(得分:0)

这个问题我遇到了同样的错误。 “锚标记处理期间发生错误。无效的文档faultcode = soap:Client faultactor = {https://demo.docusign.net/api/3.0/dsapi.asmx”“

您需要使用需要签名的附加文档中提供的所需字符串替换锚定标签字符串。

替换:

tab1.AnchorTabItem.AnchorTabString ='By:';  tab2.AnchorTabItem.AnchorTabString ='签名日期:';

收件人:

tab1.AnchorTabItem.AnchorTabString ='文档中的签名标签';  tab2.AnchorTabItem.AnchorTabString ='文档中的签名标签';