Created
January 31, 2020 07:28
-
-
Save geeky-sh/2907401ddb902652352589f88822f685 to your computer and use it in GitHub Desktop.
Docusign request signatures via email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python3 Quick start example: send an envelope to be signed. The signer is notified by email | |
# Copyright (c) 2018 by DocuSign, Inc. | |
# License: The MIT License -- https://opensource.org/licenses/MIT | |
import base64, os | |
from docusign_esign import ( | |
ApiClient, EnvelopesApi, EnvelopeDefinition, | |
Signer, SignHere, Tabs, Recipients, Document, | |
Checkbox, FirstName, Text, RecipientEvent, EventNotification) | |
# Settings | |
# Fill in these constants | |
# | |
# Obtain an OAuth access token from https://developers.docusign.com/oauth-token-generator | |
access_token = '' | |
# Obtain your accountId from demo.docusign.com -- the account id is shown in the drop down on the | |
# upper right corner of the screen by your picture or the default picture. | |
account_id = '' | |
# Recipient Information: | |
signers = ( | |
('Aash Dhariya', 'aash.discover@gmail.com'), | |
) | |
documents = ( | |
'demo_documents/dealroom.pdf', | |
'demo_documents/World_Wide_Corp_lorem.pdf' | |
) # give the proper locations of the documents over here. | |
# The document you wish to send. Path is relative to the root directory of this repo. | |
file_name_path = 'demo_documents/dealroom.pdf'; | |
base_path = 'https://demo.docusign.net/restapi' | |
# Constants | |
APP_PATH = os.path.dirname(os.path.abspath(__file__)) | |
def send_document_for_signing(): | |
""" | |
Sends the document <file_name> to be signed by <signer_name> via <signer_email> | |
""" | |
# Create the component objects for the envelope definition... | |
ddocuments = [] | |
for i, d in enumerate(documents): | |
with open(os.path.join(APP_PATH, d), "rb") as file: | |
content_bytes = file.read() | |
base64_file_content = base64.b64encode(content_bytes).decode('ascii') | |
document = Document( # create the DocuSign document object | |
document_base64 = base64_file_content, | |
name = 'RPCO_NDA', # can be different from actual file name | |
file_extension = 'pdf', # many different document types are accepted | |
document_id = i+1 # a label used to reference the doc | |
) | |
ddocuments.append(document) | |
# Create a sign_here tab (field on the document) | |
sign_here = SignHere( | |
anchor_string='*s*', anchor_units='pixels', anchor_x_offset='0', anchor_y_offset='0' | |
) | |
checkbox_1 = Checkbox( | |
anchor_string='*1*', anchor_units='pixels', anchor_x_offset='0', anchor_y_offset='0', | |
required=True | |
) | |
checkbox_2 = Checkbox( | |
anchor_string='*2*', anchor_units='pixels', anchor_x_offset='0', anchor_y_offset='0', | |
required=True | |
) | |
text_value = Text( | |
locked=True, anchor_string='*3*', anchor_x_offset='0', anchor_y_offset='0', value="Neeraj", | |
font_size='Size12', bold=True | |
) | |
sign_here_1 = SignHere( # DocuSign SignHere field/tab | |
document_id = '2', page_number = '1', tab_label = 'SignHereTab', | |
x_position = '195', y_position = '147') | |
# Add the tabs model (including the sign_here tab) to the signer | |
dsigners = [] | |
i = 1 | |
for s in signers: | |
name = s[0] | |
email = s[1] | |
signer = Signer(email=email, name=name, recipient_id=i+1, routing_order='1') | |
signer.tabs = Tabs( | |
sign_here_tabs = [sign_here, sign_here_1], checkbox_tabs=[checkbox_1, checkbox_2], text_tabs=[text_value]) | |
i+=1 | |
dsigners.append(signer) | |
recipient_event = RecipientEvent(recipient_event_status_code='Completed') | |
recipient_event_1 = RecipientEvent(recipient_event_status_code='Delivered') | |
event_notification = EventNotification( | |
url="https://eno8l2dkwu8lc.x.pipedream.net", recipient_events=[recipient_event, recipient_event_1]) | |
# Next, create the top level envelope definition and populate it. | |
envelope_definition = EnvelopeDefinition( | |
email_subject = "Please sign NDA (case of multiple documents)", | |
email_blurb='This content can be changed later', | |
# documents = [document], | |
documents = ddocuments, # The order in the docs array determines the order in the envelope | |
recipients = Recipients(signers = dsigners), # The Recipients object wants arrays for each recipient type | |
status = "sent", # requests that the envelope be created and sent. | |
event_notification=event_notification | |
) | |
# Ready to go: send the envelope request | |
api_client = ApiClient() | |
api_client.host = base_path | |
api_client.set_default_header("Authorization", "Bearer " + access_token) | |
envelope_api = EnvelopesApi(api_client) | |
results = envelope_api.create_envelope(account_id, envelope_definition=envelope_definition) | |
return results | |
# Mainline | |
results = send_document_for_signing() | |
print("\nEnvelope status: " + results.status + ". Envelope ID: " + results.envelope_id + "\n") | |
print(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment