SamiraJavdani

Unable to add document to a package

0 votes

I am trying to add documents to a package but unable to do so. I have tried two method:

i.                     Create a package and upload documents in same api call

ii.                   Create a package first and then upload documents

 

The request in both the case is the same.

 

Request:

let options = {

            url: url,

            method: "POST",

            headers: {

                Authorization: "Basic ",

                Accept: 'application/json',

                'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'

            },

            timeout: 60000,

            proxy: proxyAgt,

            formData: {

                    'file': {

                    'value': fs.createReadStream('./document/test_document_extraction.pdf'),

                    'options': {

                        'filename': 'test_document_extraction.pdf',

                        'contentType': null

                    }

                },

                'payload': signers

            }

        };

 

I am not getting a success response in either cases. The only successful response I get is when I am creating a package but upload document is not working.

 

Can you please let me know what is missing in the request being sent.


Attachments

Reply to: Unable to add document to a package

0 votes

Hi Samira,

 

Seems the client is developing with Node JS + OneSpan Sign Restful API. Given the background, I believe the first step is to help the client adjust the code and make the multipart/form-data POST call work. Please refer the client to below sample codes which work at my side:

 

 

        var request = require('request');

        var fs = require('fs');

        var jsonPayload = '{ "roles": [ { "id": "Signer1", "type": "SIGNER", "signers": [ { "firstName": "' + fields.firstName + '", "lastName": "' + fields.lastName+ '", "email": "' + fields.emailAddress + '", "id": "Signer1" } ] }, { "id": "Sender1", "type": "SIGNER", "signers": [ { "firstName": "Haris", "lastName": "Haidary", "email": "[email protected]", "id": "Sender1" } ] } ], "documents": [ { "fields": [ { "value": "' + fields.firstName + '", "name": "first_name" }, { "value": "' + fields.lastName + '", "name": "last_name" }, { "value": "' + fields.address + '", "name": "address" }, { "value": "' + fields.city + '", "name": "city" }, { "value": "' + fields.zip + '", "name": "zip" }, { "value": "' + fields.state + '", "name": "state" }, { "value": "' + fields.country + '", "name": "country" }, { "value": "' + fields.phoneNumber + '", "name": "phone_number" }, { "value": "' + fields.emailAddress + '", "name": "email" }, { "value": "' + fields.company + '", "name": "company" }, { "value": "' + fields.policyNumber + '", "name": "policy_number" } ], "name": "Sample Contract", "id" : "contract", "extract": true } ], "name": "NodeJS Example", "type": "PACKAGE", "status": "SENT" }';
 

        var options = 
        { 
            method: 'POST',
            url: 'https://sandbox.esignlive.com/api/packages',
            headers: 
            { 
                'Accept': 'application/json',
                'Authorization': 'Basic {your_api_key}',
                'Content-Type': 'multipart/form-data' 
            },
            formData: 
            { 
                'file': fs.readFileSync('sample_contract2.pdf'),
                'payload': jsonPayload 
             } 
        };

        request(options, function (error, response, body) 
        {
            if (error) throw new Error(error);

            var response = JSON.parse(body);
            console.log("The package id is: " + response['id']);                      
        });

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off