Python docassemble package for integrating with DocuSign
Project description
docassemble.docusign
A docassemble extension to allow you to access the DocuSign API from inside Docassemble interviews.
Installation
Install this package from within your Docassemble package management screen using the GitHub address.
Configuration
Docassemble-DocuSign uses the JWT authorization technique. See the DocuSign API Documentation for details.
To configure Docassemble to access your DocuSign account:
- In the DocuSign Admin system, create a docassemble-docusign app.
- Create an RSA Keypair for that app, and save the private key to a secure location.
- For that app, add https://{your.server.here}/interview as a redirect URI, or whatever your "interview" root is on your docassemble server.
- Get the integration key or "client ID" for your app.
- In the user section of your DocuSign admin system, look at the details of the user account your app will use, and get the "API Username" for that user.
Now you are ready to configure docassemble-docusign. Go into the configuration screen of docassemble, and add the following configuration lines. Remember that whitespace matters.
docusign:
client-id: {the integration key or client ID from step 4}
impersonated-user-guid: {the API Username from step 5}
test-mode: True
private-key: |
-----BEGIN RSA PRIVATE KEY-----
{the private key you saved from step 2}
-----END RSA PRIVATE KEY-----
Test Mode
If you set test-mode: True, the extension will use sandbox mode on the DocuSign API.
If you set test-mode: False, the extension will use live mode on the DocuSign API.
Authenticating
Now the extension is configured, but you need to give it permission to impersonate the DocuSign user account.
To do that run the docusign_auth.yml interview included with the package. It will send you to the right location to authorize.
Usage
Include the Module
First, include the module in your interview.
---
modules:
- docassemble.docusign.da_docusign
---
Generate DocuSign Tabs
Second, use the generate_anchor function to insert "Anchors" into your document where you want DocuSign tabs to appear.
generate_anchor accepts two parameters, the first is a DocuSign anchor type, which must be one of:
- 'approve'
- 'checkbox'
- 'company'
- 'dateSigned'
- 'date'
- 'decline'
- 'email'
- 'envelopeId'
- 'firstName'
- 'formulaTab'
- 'fullName'
- 'initialHere'
- 'lastName'
- 'list'
- 'notarize'
- 'note'
- 'number'
- 'radioGroup'
- 'signHere'
- 'signerAttachment'
- 'ssn'
- 'text'
- 'title'
- 'view'
- 'zip'
The second parameter is the email address of the person who needs to fill out that tab.
For example, you can create a template in your docassemble interview as follows:
attachments:
- name: Your Document
filename: docusign_test_doc
variable name: docusign_test_doc
content: |
% for r in recipient:
${ generate_anchor('signHere', r.email) }
***
${ r.name }
${ generate_anchor('date', r.email) }
% endfor
That code will generate an anchor for the signature, followed by a horizontal line, followed by the person's name, followed by an anchor for the date on which they signed the document.
Create the DocuSign Envelope Parameters
Next, your code needs to create a Python object for the recipients portion of the DocuSign envelope, and a python object for the documents portion of the DocuSign Envelope.
Note that when you are generating your recipients object, you must include all the same tabs that you generated anchors for in the
document, to ensure that DocuSign will deal properly with them. When generating tabs, use the generate_anchor function.
An example of a correctly formated recipients object is:
recipients=[
{
'name': 'Doug Rattman',
'email': 'doug.rattman@aperturescience.com',
'group': 'signers',
'routingOrder': 1,
'tabs': [
{
'type': 'signHere',
'anchorString': generate_anchor('signHere', 'doug.rattman@aperturescience.com')
},
{
'type': 'date',
'anchorString': generate_anchor('date', 'doug.rattman@aperturescience.com')
}
]
},
{
'name': 'Cave Johnson',
'email': 'ceo@aperturescience.com',
'group': 'certifiedDeliveries',
'routingOrder': 2
}
]
See the DocuSign API documentation for information on the features that are available in DocuSign envelopes.
The generate_anchor function has an optional argument uid that will add an additional section to the anchor. Use this is if you want to distinguish between tags of the same type.
When generating documents, use the make_document_base64 function to convert the document to Base64 before adding it to the object.
make_document_base64 accepts a path to a document. If you want to use a dynamically-generated document in a Docassemble interview,
give that document a variable name: attribute, and then use document_variable_name.pdf.path(), replacing pdf with whatever
document format you prefer.
An example of a correctly formatted documents object is:
documents=[
{
'name': "Bring Your Daughter To Work Day",
'fileExtension': 'docx',
'documentBase64': make_document_base64('bydtwd.docx')
},
{
'name': "Lemon Grenade Acquisition",
'fileExtension': 'docx',
'documentBase64': docasign.make_document_base64('lemongrenadeacquisition.docx')
}
]
There is an example interview provided in the package, docusign_test_interview.yml, that has an example of generating the
recipient and document objects in code.
Send the Envelope to DocuSign
In your interview code, create a DocuSign() object:
code: |
ds = DocuSign()
Then, call the get_signatures() function to send your documents to your recipients.
get_signatures accepts the following parameters:
recipients: Mandatory. The recipients object described above.documents: Mandatory. The documents object described above.send_immediately: Optional, if set toTrue, your request will be sent. IfFalse,email_subject: optional, defaults to "Please Sign".assign_doc_ids: optional, deafults toTrue. Set toFalseif you are manually setting document IDs in your document object.assign_recipient_ids: optional, deafaults toTrue. Set toFalseif you are manually setting recipient IDs in your recipients object.
Any other paramaters will be added as additional parts of the request sent, for example, emailBlurb="Please sign this document" sets the email's body.
get_signatures returns the JSON formatted version of your DocuSign envelope when send_immediately is False.
If send_immediately is set to True, then it returns three values:
- the JSON formatted version of the DocuSign envelope
- the response data of the DocuSign Server
- the status code of the request to the DocuSign Server
A successful envelope submission will return a status code of 201.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docassemble.docusign-0.2.1.tar.gz.
File metadata
- Download URL: docassemble.docusign-0.2.1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41b3d3916db02f4e20250441e4e1cdfd0837c4e2b97a9979a1528ee687c02f10
|
|
| MD5 |
3c183b3d6dc42b7bf8a78b34aa874231
|
|
| BLAKE2b-256 |
1a38a8c58a9c889e1b9d1aa0563f11378c80191b1d04ef1a4d03298b02f2dfc5
|
File details
Details for the file docassemble.docusign-0.2.1-py3-none-any.whl.
File metadata
- Download URL: docassemble.docusign-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f41f4345fdfd2e55d299f9d5b9fcf49834bf77ebf8709181986221814b246f50
|
|
| MD5 |
1edaf490e276d7d3689967e3ffe8e32e
|
|
| BLAKE2b-256 |
b25f453ee34379f9c70af19b3eb82b1067a2d07186e7f4d058263a67d5e17156
|