How to upload html document using Docusign REST API - docusignapi

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?

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.

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

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

Word Addin - How to open a file as a new document?

I am developing a Word add-in using Office JS in which a user can decide to open a document from a remote server API. In that case I need to receive a file from the server API and open it in Word.
Currently, I am making an HTTP request to get the document contents from the remote server encoded in Base64.
Then I am using:
var body = context.document.body;
body.insertFileFromBase64 (fileData, Word.InsertLocation.replace);
// (where fileData is the Base64 content)
This works (document is actually opened), but I don't like it so much because it replaces the current document's contents instead of opening a new document.
Is there a way to make Word open a document as a new document instead of replacing the existing document's contents?
I described my use case above in case you can also suggest a better solution.
there is an API, in preview, you can use for this. here is a code snippet:
(note that the createDocument takes an optional parameter, a base64-encoded docx) if that's provided the opened document will include it.
in order to test the API make sure to use the preview CDN for Office.js avilable here https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
and that you have a fresh update of Office.
here is the code:
Word.run(function (context) {
context.application.createDocument().open(); // optionally on createDocument send a base-64 docx.
return context.sync();
})

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.

Append Rich Text Item to MIME

I have a submit only XPage based form that has an inputRichText field for storing screenshots and a multi file upload (using the XPages Multiple File Uploader from OpenNTF) for uploading one or more attachments. When submitted I need both the screenshots and the attachments to appear in a single rich text field which will be accessed via the Notes Client only (non XPages).
Currently the form stores the attachments and screenshots in separate fields. I have tried appending one field to the other on save (using SSJS in the submit button, however because the Screenshots are stored as MIME and the attachments as NotesRichText, it is not letting me do it.
Is there some way (preferably in SSJS) that I can convert either the MIME to RichText or vice versa so that I can append one field to the other? I have tried searching for various solutions to no avail, as well as trying different file upload controls from OpenNTF.
Ideally I need something like this to work:
var rtItemAttachments:NotesRichTextItem = docTo_Backend.getFirstItem("attachments"); //This is the field I want everything in
var rtItemFiles:NotesRichTextItem = docTo_Backend.getFirstItem("uploadedFiles");
rtItemAttachments.appendRTItem(rtItemFiles); //Fails on this line
docTo_Backend.removeItem("uploadedFiles");
Speak after me: there is no RichText in the web, all there is is MIME.
You can set the RT field to store its content in MIME (a property). This makes things much easier.
To stitch things together you need to stick with MIME. These are roughly the steps
Get the text and images as MIME
Get your attachments as stream (the embeddedObjects has a method for that)
Convert the stream to BASE64 and create a new mime-part with it. (Looking at an attachment eMail source someone sent through the internet should give you a pretty good idea how it looks like)
You end up with:
MimeHeader
MimePart for Text (HTML)
MimePart for Screenshots (if they are not inline images in html)
MimeParts for attachments
The special effect: if you add to the HTML with links to the attachments, it looks nicer.
Of course the BIG question: WHY?
You could simply design a Notes form that has two fields, no need to fold it into one. Hope that helps.
A good piece of code to look at to understand the MIME stuff is the OpenNTF eMail bean

Resources