coder87 | Posts: 1

When trying to add document as binary data to create package I always get an error

0 votes

Hello,

I am having some issues when trying to add a document as binary data to a package

Our pdf's are in base64 data so we need to convert this data to binary data but we always get this error when we are trying to create new package(POST /api/packages):
 

data: {
    messageKey: 'error.validation.documentPreVerifyInvalidResponseNumberError',
    parameters: {
      errorException: 'number of documents that need verification = 2, number of verification results = 0'
    },
    message: 'The number of Pre-Verify results does not match the number of documents that were sent for verification.',
    code: 400,
    name: 'Validation Error'
  }

 

I think something is wrong with binary data because it has some strange characters. What type should be used for encoding(utf-8, binary...) ? 

 

and when I try to save this data as pdf, pdf is broken, I've created pdf from the data, file is attached

 

node js code

 

const buffer = Buffer.from(`${base64String}`, 'base64')

const stream = Readable.from(buffer.toString('utf-8'))

 

const getData = async () => {

  const fileData = await stream_to_string(stream)

  await create_package(fileData, 'Testing 1')

}

 

getData()

 

and this is create_package function

 

const create_package = async (file, name) => {

  let body = {

    payload: {

      "roles": [

        {

          "id": "Role1",

          "index": 0,

          "signers": [

            {

              "email": "[email protected]",

              "firstName": "John",

              "lastName": "Doe"

            }

          ]

        }

      ],

      "documents": [

        {

          "approvals": [

            {

              "role": "Role1",

              "fields": [

                {

                  "page": 0,

                  "top": 100,

                  "subtype": "FULLNAME",

                  "height": 50,

                  "left": 100,

                  "width": 200,

                  "type": "SIGNATURE"

                }

              ]

            }

          ],

          "name": "test.pdf"

        }

      ],

      "name": `${name}`,

      "type": "PACKAGE",

      "language": "fr",

      "emailMessage": "",

      "description": "",

      "autocomplete": true,

      "status": "SENT"

    },

    file: file

  }

 

  const formData = new FormData()

  formData.append('payload', JSON.stringify(body.payload))

  formData.append('file', body.file)

  try {

    const res = await axios.post(`https://sandbox.esignlive.com/api/packages/`, formData, {

      headers: {

        'Authorization': `Basic api_key`,

        ...formData.getHeaders()

      }

    })

    console.log(res.data)

  } catch (err) {

    console.log(err.response)

  }

}


Attachments
testing1.pdf13.58 KB
Approved Answer
Duo_Liang | Posts: 3776

Reply to: When trying to add document as binary data to create package I always get an error

0 votes

Hi coder87,

 

Thanks for your post! Not very sure how "axios" internally works, but with "request", you are able to directly use Buffer object as the formData:
 

    const buffer = Buffer.from('base64_string', 'base64')
    const options = 
    { 
        method: 'POST',
        url: 'https://sandbox.esignlive.com/api/packages',
        headers: 
        { 
            'Accept': 'application/json',
            'Authorization': 'Basic ' + api_key,
            'Content-Type': 'multipart/form-data' 
        },
        formData: 
        { 
            'file': buffer,
            'payload': jsonPayload 
         } 
    };

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

        console.log(body)

                  
    });

 

PS: The testing1.pdf you uploaded seems to be corrupted, but not sure if it's related to the issue itself.

 

Duo


TimMillerDyck | Posts: 10

Reply to: When trying to add document as binary data to create package I always get an error

1 votes

Hi, for others finding this page, I was also getting 'The number of Pre-Verify results does not match the number of documents that were sent for verification.' and 'number of documents that need verification = 2, number of verification results = 0' back from the OneSpan REST API.

The issue was actually corruption in the PDF I was sending. I had incorrectly base64-encoded a test PDF and the resulting decoded byte stream I was using to test with OneSpan was not the same bytes as the original PDF.

So, I would suggest anyone seeing this error double-check that the PDF bytes they are actually sending to the OneSpan REST API are correct.


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