DocuSign eSign REST API How to handle PDF response in PHP? - docusignapi

I'm trying to get all documents in an envelope as a single PDF, if I call this REST API URL:
/v2/accounts/{$accountId}/envelopes/{$envelopeId}/documents/combined
It returns a bunch of data, however, I can't find a way to store this data as a valid PDF. When I output the content with headers it does download a file, but it's not a valid PDF. Also when I store the content in a file, it will not be a valid PDF file.
Anyone encountered this problem and knows how to solve this?

The content comes back as a file, you have to read the temp file and save that to the desired file
Quick snippet using file_get_contents and file_put_contents
$docStream = $envelopeApi->getDocument($accountId, 1, $envelopeId);
file_put_contents("my_document.pdf", file_get_contents($docStream->getPathname()));
More info DocuSign REST API :: EnvelopeDocuments: get under Get a Single Document as a PDF File

Related

Is there a way to get the file type of a document in an envelope (without extension)?

I am interesting in obtaining the file type (e.g. PDF, Word doc) of documents sent in an envelope. Of course this could be done just by getting the extension from the file name, but if a filename does not have an extension, is there an API call that would give me the file's type?
You cannot do this. Once the document is uploaded to DocuSign, it's always converted into a PDF. The original is not stored anywhere. You can have code that uses custom fields to store this information, but other than that - you would have to use the file name and the extension in there.

Reading Excel File from GET Request (Node)

I am trying to grab values from an excel spreadsheet that has been uploaded to a CRM called "Zoho" and the only way to read the file is to download the file through Zoho's own API. However, when trying to download an .xlsx file through the API, the file is encoded and I cannot figure out how to decode it and read the file. The request, when completed, returns a plaintext file with many question marks in it. What is the correct way to decode the file/is there a better way I could be doing this? Ultimately I want to read the value from the file, then make another request to another API to update a value; at no point do I need to download the excel file locally.
Here is the documentation for the Zoho API: https://www.zoho.com/docs/zoho-docs-api.html
Here is a code snippet where I make a request:
And finally this is what the result looks like:
Any help would be greatly appreciated!

How to upload html document using Docusign REST API

I have my code working to upload a PDF document, but I am trying to get it to upload an HTML document and having trouble. My code that works for the PDF document is this:
$documents = new Document();
$documents->setName($doc_name . '.pdf');
$documents->setDocumentId(1);
$documents->setFileExtension('pdf');
$file = file_get_contents($file_url);
$documents->setDocumentBase64(base64_encode($file));
But when I try to do this with an HTML document it fails. My HTML attempt uses this:
$documents = new Document();
$documents->setName($doc_name . '.pdf');
$documents->setDocumentId(1);
$documents->setFileExtension('html');
$documents->setDocumentBase64(base64_encode($html));
When I try this using the REST API Explorer I get this error message:
System was unable to convert this document to a PDF. Unable to convert Document(SampleHTML) to a PDF. Error: UserId:xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx IPAddress:54.213.184.61 Source:ApiRESTv2:FileType UNKNOWN is ineligible for conversion.
I have read that html is an accepted file type, so I am pretty sure this is possible. I could cover to PDF on my server and send, but would rather pass that off to Docusign.
Any help is greatly appreciated.
Thom
The DocuSign platform does indeed accept multiple document formats, however there may be a difference between what the DS Apps accept and what the API accepts. The list of supported document types that you can send through the DocuSign Console can be found here:
https://support.docusign.com/guides/ndse-user-guide-supported-file-formats
However I'm not sure if .html is an accepted file format when sending through the API. I thought there might be security issues with that but not positive at this point. In either case, even though you are setting the fileExtension property it looks like you are still sending a document with a filename that ends with .pdf, have you tried removing that or changing to .html?

PDF form to HTML conversion in angular 2?

In my application I am uploading a PDF file after uploading, I should display the information present in PDF file to a HTML form we are using angular 2 for frontend and node js for backend. Can any one help me with this.
Please remember PDF to HTML.
You can do one thing. Convert your pdf to a JSON. Use pdf2json.
pdf2json is a node.js module that parses and converts PDF from binary to json format, it's built with pdf.js and extends it with
interactive form elements and text content parsing outside browser.
The goal is to enable server side PDF parsing with interactive form
elements when wrapped in web service, and also enable parsing local
PDF to json file when using as a command line utility.
perform npm install pdf2json
Create an empty JSON whose key values will be the main headings from the pdf like a customer, age etc. Its values are obtained from the uploaded pdf.
Using this JSON values fill your form, on saving the form using, node.js save it to your DB. Is this what you want?
Simply what you need is to render a PDF in your application.
You could use this library ng2-pdf-viewer
Almost all the basic functionalities are available as properties to this component. You could manipulate it to your requirement.

Post DocuSign Envelope with base64 string failed for non-pdf file

I'm trying to post an envelope but it keeps failing for non-pdf file with the following failure:
<errorCode>UNABLE_TO_LOAD_DOCUMENT</errorCode>
<message>Unable to load the document. Unable to load Document(1;Parking Application). Error: the document is corrupt, rebuilding failed </message>
I know that I can trying sending the document as multi-part request but I'm wondering what is the issue in this request:
https://drive.google.com/file/d/0B4IcppTb9svVSFhXYkdFa0gtbms/view
it contains a word document.
It doesn't seem to be an issue with the base64 encoded string because the string can be decoded back to the file just fine e.g. using http://www.motobit.com/util/base64-decoder-encoder.asp
You forgot to include the
<fileExtension>docx</fileExtension>
node in your XML adjacent to the documentBase64 node.
(The snippet above assumes you're sending a docx file. Change it to whatever the filetype is.)
In other words, if your document is not a pdf, you need to tell the platform what the format of your documents are. It assumes pdf.

Resources