docusign_rest
docusign_rest copied to clipboard
Adding an attachment to an envelope
Hi,
I have been tasked with adding a dynamically generated attachment to a docusign envelope and then send the document. Currently there is the add_envelope_document method, however that requires a document ID, which obviously doesn't work if you're generating the on the fly.
I took a look at the documentation (https://docs.docusign.com/esign/restapi/Envelopes/EnvelopeAttachments/create/) and found that this should work. I wrote this up, but I wanted to see if this was an addition that anybody else wants? It's basically just a different version of add_envelope_document except it takes a base64 encoded string.
Sounds good to me!
Do you think it would work ok to modify the existing add_envelope_document
method to check for a document_contents
entry in the options
hash? Or do you think it'd be better with a whole new method? I guess I'd lean towards modifying the existing method, but I don't know how much it would have to change...
@awlamb Are you tasked with adding a dynamic document to an already existing envelope? Or creating a dynamic document to attach to a new envelope?
The document_id
is just a unique number for the docusign side, it doesn't have to link back to anything in your system. In the examples in the readme it's hard coded to 1
. That document doesn't yet exist in the rails app / that ID isn't being pulled from a database. I'd recommend hard coding it and using the flow the example in the readme highlights. Unless you do need a more complicated workflow than that?
@jondkinney Oh Interesting - yes, it's a dynamically generated PDF attaching to a newly created envelope. It actually doesn't look like I can pass a string as file to that method, unless I'm incorrect:
open(options[:file_path]).read
while the other method to add attachments asks for a base64 encoded string. Looks like that may be the only difference though. Thoughts?
Are you able to create a temp file to feed in? Even on Heroku with an ephemeral file system, I'm pretty sure you can count on the temp file being there through the request at least. If not, I'm sure it's possible to alter the create_envelope_from_document
method call to accept a file param as a base64 encoded string. At the end of the day it's all getting converted to a string to pipe into a Net::HTTP::Post::Multipart call. Take a look at the create_file_ios(files)
method in client.rb
for some inspiration.
Actually tried that this morning and encountered a different issue:
invalid byte sequence in UTF-8 /docusign_rest/lib/docusign_rest/client.rb:1718:in 'gsub' /docusign_rest/lib/docusign_rest/client.rb:1718:in 'generate_log' /docusign_rest/lib/docusign_rest/client.rb:1623:in 'add_envelope_document'
This was with a regular old pdf document i was trying locally.
I also noticed this in the docs:
Documents can be included with the Envelopes:create method, or a template can include documents. Documents can be added by using a multipart/form request or by using the documentBase64 property of the document object.
Although not the same endpoint, it's probable that the procedure is the same.
Unfortunately I can't seem to get multipart/form-data working for that document endpoint. However, a docusign support engineer told me to just do this:
Endpoint: https://{environment}.docusign.net/restapi/v2/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId} · Headers: X-DocuSign-Authentication (with integrator key and credentials) and Content-Type as application/json · Body: { "documentBase64": "{document in base64}", "documentId": "{documentId}", "fileExtension": "{extension, for example doc, pdf}", "name": "{document name}" }