def worker(args): """ 1. Create an api client 2. Create an envelope definition object 3. Call the eSignature REST API using the SDK """ # Step 1: Construct your API headers api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) # Step 2: Construct your envelope envelope_definition = EnvelopeDefinition( email_subject="Please sign this document set") # Open the example file with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") # Add a Document document1 = Document( # create the DocuSign document object document_base64=base64_file_content, document_id="1", # a label used to reference the doc file_extension="pdf", # many different document types are accepted name="Lorem" # can be different from actual file name ) envelope_definition.documents = [document1] envelope_definition.status = args["envelope_args"]["status"] signer1 = Signer( email=args["envelope_args"] ["signer_email"], # represents your {signer_name} name=args["envelope_args"] ["signer_name"], # represents your {signer_email} access_code=args["envelope_args"]["recip_access_code"], # represents your {ACCESS_CODE} for your recipient to access the envelope recipient_id="1", routing_order="1") # Create your signature tab sign_here1 = SignHere( name="SignHereTab", x_position="75", y_position="572", tab_label="SignHereTab", page_number="1", document_id="1", # A 1- to 8-digit integer or 32-character GUID to match recipient IDs on your own systems. # This value is referenced in the Tabs element below to assign tabs on a per-recipient basis. recipient_id="1" # represents your {RECIPIENT_ID} ) # Add the tabs model (including the sign_here tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1]) # Tabs are set per recipient envelope_definition.recipients = Recipients(signers=[signer1]) # Step 3: Call the eSignature REST API envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( account_id=args["account_id"], envelope_definition=envelope_definition) return results
def make_envelope(cls, args): """ Creates envelope: document 1 (HTML) has signHere anchor tag: **signature_1** document 2 (DOCX) has signHere anchor tag: /sn1/ document 3 (PDF) has signHere anchor tag: /sn1/ DocuSign will convert all of the documents to the PDF format. The recipient’s field tags are placed using anchor strings. The envelope has two recipients: recipient 1: signer recipient 2: cc The envelope will be sent first to the signer via SMS. After it is signed, a copy is sent to the cc recipient via SMS. """ # Create the envelope definition env = EnvelopeDefinition(email_subject="Please sign this document set") doc1_b64 = base64.b64encode(bytes(cls.create_document1(args), "utf-8")).decode("ascii") # Read files 2 and 3 from a local folder # The reads could raise an exception if the file is not available! with open(path.join(demo_docs_path, DS_CONFIG["doc_docx"]), "rb") as file: doc2_docx_bytes = file.read() doc2_b64 = base64.b64encode(doc2_docx_bytes).decode("ascii") with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: doc3_pdf_bytes = file.read() doc3_b64 = base64.b64encode(doc3_pdf_bytes).decode("ascii") # Create the document models document1 = Document( # Create the DocuSign document object document_base64=doc1_b64, name= "Order acknowledgement", # Can be different from actual file name file_extension="html", # Many different document types are accepted document_id="1" # A label used to reference the doc ) document2 = Document( # Create the DocuSign document object document_base64=doc2_b64, name="Battle Plan", # Can be different from actual file name file_extension="docx", # Many different document types are accepted document_id="2" # A label used to reference the doc ) document3 = Document( # Create the DocuSign document object document_base64=doc3_b64, name="Lorem Ipsum", # Can be different from actual file name file_extension="pdf", # Many different document types are accepted document_id="3" # A label used to reference the doc ) # The order in the docs array determines the order in the envelope env.documents = [document1, document2, document3] phoneNumber = RecipientPhoneNumber(country_code=args["country_code"], number=args["phone_number"]) sms_notification = RecipientAdditionalNotification( phone_number=phoneNumber) sms_notification.secondary_delivery_method = "SMS" # Create the signer recipient model signer1 = Signer(email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1", additional_notifications=[sms_notification]) # Create a RecipientPhoneNumber and add it to the additional SMS notification ccPhoneNumber = RecipientPhoneNumber( country_code=args["cc_country_code"], number=args["cc_phone_number"]) cc_sms_notification = RecipientAdditionalNotification( phone_number=ccPhoneNumber) cc_sms_notification.secondary_delivery_method = "SMS" # Create a cc recipient to receive a copy of the documents cc1 = CarbonCopy(email=args["cc_email"], name=args["cc_name"], recipient_id="2", routing_order="2", additional_notifications=[cc_sms_notification]) # routingOrder (lower means earlier) determines the order of deliveries # to the recipients. Parallel routing order is supported by using the # same integer as the order for two or more recipients # Create signHere fields (also known as tabs) on the documents # We're using anchor (autoPlace) positioning # # The DocuSign platform searches throughout your envelope"s # documents for matching anchor strings. So the # signHere2 tab will be used in both document 2 and 3 since they # use the same anchor string for their "signer 1" tabs sign_here1 = SignHere(anchor_string="**signature_1**", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") sign_here2 = SignHere(anchor_string="/sn1/", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") # Add the tabs model (including the SignHere tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2]) # Add the recipients to the envelope object recipients = Recipients(signers=[signer1], carbon_copies=[cc1]) env.recipients = recipients # Request that the envelope be sent by setting status to "sent" # To request that the envelope be created as a draft, set to "created" env.status = args["status"] return env
def send_document_for_signing(summary): """ Sends the document <file_name> to be signed by <signer_name> via <signer_email> """ # Create the component objects for the envelope definition... # with open(os.path.join(APP_PATH, file_name_path), "rb") as file: # content_bytes = file.read() # base64_file_content = base64.b64encode(content_bytes).decode('ascii') base64_file_content = base64.b64encode( bytes(create_document(summary)).encode("utf-8")).decode("ascii") document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Example document', # can be different from actual file name file_extension='html', # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer( # The signer email=signer_email, name=signer_name, recipient_id="1", routing_order="1") # Create a sign_here tab (field on the document) sign_here = SignHere(anchor_string="**signature_1**", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") # sign_here = SignHere( # DocuSign SignHere field/tab # d = '1', page_number = '1', recipient_id = '1', tab_label = 'SignHereTab', # x_position = '195', y_position = '147') # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from the Python SDK", documents=[ document ], # The order in the docs array determines the order in the envelope recipients=Recipients( signers=[signer] ), # The Recipients object wants arrays for each recipient type status="sent" # requests that the envelope be created and sent. ) # 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
def send_envelope(self): self.check_token() # document 1 (html) has sign here anchor tag **signature_1** # document 2 (docx) has sign here anchor tag /sn1/ # document 3 (pdf) has sign here anchor tag /sn1/ # # The envelope has two recipients. # recipient 1 - signer # recipient 2 - cc # The envelope will be sent first to the signer. # After it is signed, a copy is sent to the cc person. args = { 'signer_email': DSConfig.signer_email(), 'signer_name': DSConfig.signer_name(), 'cc_email': DSConfig.cc_email(), 'cc_name': DSConfig.cc_name(), } # create the envelope definition env = EnvelopeDefinition(email_subject='Please sign this document set') doc1_b64 = base64.b64encode(bytes(self.create_document1(args), 'utf-8')).decode('ascii') # read files 2 and 3 from a local directory # The reads could raise an exception if the file is not available! with open(path.join(demo_docs_path, DOC_2_DOCX), "rb") as file: doc2_docx_bytes = file.read() doc2_b64 = base64.b64encode(doc2_docx_bytes).decode('ascii') with open(path.join(demo_docs_path, DOC_3_PDF), "rb") as file: doc3_pdf_bytes = file.read() doc3_b64 = base64.b64encode(doc3_pdf_bytes).decode('ascii') # Create the document models document1 = Document( # create the DocuSign document object document_base64=doc1_b64, name='Order acknowledgement', # can be different from actual file name file_extension='html', # many different document types are accepted document_id='1' # a label used to reference the doc ) document2 = Document( # create the DocuSign document object document_base64=doc2_b64, name='Battle Plan', # can be different from actual file name file_extension='docx', # many different document types are accepted document_id='2' # a label used to reference the doc ) document3 = Document( # create the DocuSign document object document_base64=doc3_b64, name='Lorem Ipsum', # can be different from actual file name file_extension='pdf', # many different document types are accepted document_id='3' # a label used to reference the doc ) # The order in the docs array determines the order in the envelope env.documents = [document1, document2, document3] # Create the signer recipient model signer1 = Signer(email=args['signer_email'], name=args['signer_name'], recipient_id="1", routing_order="1") # routingOrder (lower means earlier) determines the order of deliveries # to the recipients. Parallel routing order is supported by using the # same integer as the order for two or more recipients. # create a cc recipient to receive a copy of the documents cc1 = CarbonCopy(email=args['cc_email'], name=args['cc_name'], recipient_id="2", routing_order="2") # Create signHere fields (also known as tabs) on the documents, # We're using anchor (autoPlace) positioning # # The DocuSign platform searches throughout your envelope's # documents for matching anchor strings. So the # signHere2 tab will be used in both document 2 and 3 since they # use the same anchor string for their "signer 1" tabs. sign_here1 = SignHere(anchor_string='**signature_1**', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') sign_here2 = SignHere(anchor_string='/sn1/', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') # Add the tabs model (including the sign_here tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2]) # Add the recipients to the envelope object recipients = Recipients(signers=[signer1], carbon_copies=[cc1]) env.recipients = recipients # Request that the envelope be sent by setting |status| to "sent". # To request that the envelope be created as a draft, set to "created" env.status = "sent" envelope_api = EnvelopesApi(SendEnvelope.api_client) results = envelope_api.create_envelope(SendEnvelope.accountID, envelope_definition=env) return results