function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AkiraDioAkiraDio 

The problem with using DocuSign API from apex class.

Hello!

I want to access the DocuSign API in your Force.com / Salesforce.com account in order to send an object with a single click of a button.

I usee this manual: http://developer.force.com/cookbook/recipe/accessing-docusign-api-from-salesforcecom-to-send-contracts-for-esignatures

The problem is such that when you click on the button I get an error:

Exception - System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: An Error Occurred during anchor tag processing. Invalid document faultcode=soap:Client faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx

Code:

public class Test
{
    private final Opportunity Opp;   
    public String envelopeId {get;set;}
    private String accountId = 'xxxxxx';
        //private String accountId = '001e0000007fBIV';
    private String userId = 'xxxxxxx';    
    private String password = 'xxxxxxxx';
    private String integratorsKey = 'xxxxxxxxx';
    private String webServiceUrl
        = 'https://demo.docusign.net/api/3.0/dsapi.asmx?op=CreateAndSendEnvelope';      
       
    public Test()
    {                         
        Opp = [select id from Opportunity where id='006e0000003EEUf' limit 1];
        envelopeId = 'Not sent yet';    
        //SendNow();
    }
    public void SendNow()
    {
        DocuSignAPI.APIServiceSoap dsApiSend
            = new DocuSignAPI.APIServiceSoap();
        dsApiSend.endpoint_x = webServiceUrl;
        //Set Authentication
        String auth = '<DocuSignCredentials><Username>'+ userId
            +'</Username><Password>' + password
            + '</Password><IntegratorKey>' + integratorsKey  
            + '</IntegratorKey></DocuSignCredentials>';
        System.debug('Setting authentication to: ' + auth);        
        dsApiSend.inputHttpHeaders_x = new Map<String, String>();
        dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication',
            auth);
                DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope();
        envelope.Subject = 'Please Sign this Contract: '
            + contract.ContractNumber;
        envelope.EmailBlurb = 'This is my new eSignature service,'+
            ' it allows me to get your signoff without having to fax, ' +
            'scan, retype, refile and wait forever';
        envelope.AccountId  = accountId;    
        
                // Render the contract
        System.debug('Rendering the contract');
        PageReference pageRef = new PageReference('/apex/Test');
        Blob pdfBlob = pageRef.getContent();   
        
        // Document
        DocuSignAPI.Document document = new DocuSignAPI.Document();
        document.ID = 1;
        document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
        document.Name = 'Booking Details';
        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 = '003e0000005P1fw'];
        
        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;
        
        recipient.RequireIDLookup = false;          
        envelope.Recipients = new DocuSignAPI.ArrayOfRecipient();
        envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
        envelope.Recipients.Recipient[0] = recipient;        
        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;
        }
                            
    }
}

 Call:

    <apex:form >
                                                        <apex:commandButton value="OK" styleClass="submitButtonNew"
                                                            action="{!SendNow}" />
   </apex:form>

 

Need help!