Home > Mobile >  DocuSign API Javascript SDK - getDocument returns string
DocuSign API Javascript SDK - getDocument returns string

Time:10-07

I am trying to call the api endpoint getDocument via Node, and am expecting a Buffer to be returned, however, it is returning a string. Even when I pass in different values for the encoding optional parameter, the data returned is always the same.

When I tested the same endpoint in C#, a MemoryStream is returned which is expected.

My code is as follows:

const document = await envelopesApi.getDocument(accountId, envelopeId, '1')

Where 1 is the documentId (page 1).

The contents of document looks like %PDF-1.5\n%ûüýþ\n%Writing objects... and so on

I am then trying to save this to a file:

fs.writeFileSync('test.pdf', Buffer.from(documentContent))

With no success. How do I get the api response and save it to a file for viewing?

CodePudding user response:

Yes, this is correct, you will have to use the correct mime type for PDF (in this case) in order to show this file in the browser.

You can find a node.JS code example that shows you how to do this.

But the most important part in your case would be this line:

mimetype = "application/pdf";
  • Related