def make_envelope(file, sender, signer_name, signer_email, token): file.seek(0) content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64=base64_file_content, name='DocuScan Terms', file_extension='html', document_id=1) signer = Signer(email=signer_email, name=signer_name, recipient_id='1', routing_order='1') envelope_definition = EnvelopeDefinition( email_subject='Please sign these terms', documents=[document], recipients=Recipients(signers=[signer]), status='sent') api_client = ApiClient() api_client.host = 'https://demo.docusign.net/restapi' api_client.set_default_header('Authorization', 'Bearer ' + token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( sender['accounts'][0]['account_id'], envelope_definition=envelope_definition) return results
def send_envelope(self): self.check_token() envelope = self.create_envelope() envelope_api = EnvelopesApi(SendEnvelope.api_client) results = envelope_api.create_envelope(SendEnvelope.accountID, envelope_definition=envelope) return results
def send_document_for_signing(loan_id, signer_name, signer_email): APP_PATH = os.path.dirname(os.path.abspath(__file__)) access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjY4MTg1ZmYxLTRlNTEtNGNlOS1hZjFjLTY4OTgxMjIwMzMxNyJ9.eyJUb2tlblR5cGUiOjUsIklzc3VlSW5zdGFudCI6MTU3NTY5MDA3NywiZXhwIjoxNTc1NzE4ODc3LCJVc2VySWQiOiI5YmM2MWNiZC1lMjA2LTQ4ZmYtOGE2OC1mZGM0ZGNlMWRhOWUiLCJzaXRlaWQiOjEsInNjcCI6WyJzaWduYXR1cmUiLCJjbGljay5tYW5hZ2UiLCJvcmdhbml6YXRpb25fcmVhZCIsImdyb3VwX3JlYWQiLCJwZXJtaXNzaW9uX3JlYWQiLCJ1c2VyX3JlYWQiLCJ1c2VyX3dyaXRlIiwiYWNjb3VudF9yZWFkIiwiZG9tYWluX3JlYWQiLCJpZGVudGl0eV9wcm92aWRlcl9yZWFkIiwiZHRyLnJvb21zLnJlYWQiLCJkdHIucm9vbXMud3JpdGUiLCJkdHIuZG9jdW1lbnRzLnJlYWQiLCJkdHIuZG9jdW1lbnRzLndyaXRlIiwiZHRyLnByb2ZpbGUucmVhZCIsImR0ci5wcm9maWxlLndyaXRlIiwiZHRyLmNvbXBhbnkucmVhZCIsImR0ci5jb21wYW55LndyaXRlIl0sImF1ZCI6ImYwZjI3ZjBlLTg1N2QtNGE3MS1hNGRhLTMyY2VjYWUzYTk3OCIsImF6cCI6ImYwZjI3ZjBlLTg1N2QtNGE3MS1hNGRhLTMyY2VjYWUzYTk3OCIsImlzcyI6Imh0dHBzOi8vYWNjb3VudC1kLmRvY3VzaWduLmNvbS8iLCJzdWIiOiI5YmM2MWNiZC1lMjA2LTQ4ZmYtOGE2OC1mZGM0ZGNlMWRhOWUiLCJhdXRoX3RpbWUiOjE1NzU2OTAwMDYsInB3aWQiOiIyZjA5MDc4Yy0yMzdiLTQ1ODMtYWI0MS1jOGM4NTg2MDllZmYifQ.wrcjGaFQTDAZ2NpYcT4i40hboJyc4s1NGNodhN0VEEWh-XuM5cmHJJQECEueGf3UA9taUjupFbI86JxMkpx9GqebBBNCT6UyHBq0GPbhy85nR2ktgYi6ZbcBJvxiLdWwd3IkrC0a-4GVAgqdp1pXVe79f4nPMmRzCvKMIsdlUUVcQCacPU7hgHNuZhwwPikQKO1WDEBCD8epv4qbil4_Er73It3-DNMNYa4yqaaQ64rb_xTOAwYZ4Ua3w6gW2Vot6zBIt-Gm1Go8GgDrzrAxES5W0e6DtQMUq48q9Kiba5YhdnZSXLC1yJIb2ma_p0j1NYW-Pu0WMjjK8Y_-4B6RpQ' account_id = '5959504' file_name_path = 'documents/approval_letter.pdf' base_path = 'https://demo.docusign.net/restapi' # 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') document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Approval Letter', # can be different from actual file name file_extension='pdf', # 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( # DocuSign SignHere field/tab document_id='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 Approval Letter for your loan.", 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. ) # send 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 embedded_signing_ceremony(signer_email, signer_name, signer_id, signer_file_path, signer_file_name, form_filled_type): with open(os.path.join(APP_PATH, signer_file_path), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64 = base64_file_content, name = signer_file_name, file_extension = 'pdf', document_id = 1) signer = Signer(email = signer_email, name = signer_name, recipient_id = "1", routing_order = "1", client_user_id = signer_id) sign_here = SignHere(document_id = '1', page_number = '1', recipient_id = '1', tab_label = 'SignHereTab', x_position = '300', y_position = '650') signer.tabs = Tabs(sign_here_tabs = [sign_here]) envelope_definition = EnvelopeDefinition( email_subject = "Please sign this document sent from the Python SDK", documents = [document], recipients = Recipients(signers = [signer]), status = "sent" ) 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) envelope_id = results.envelope_id recipient_view_request = RecipientViewRequest(authentication_method = "email", client_user_id = signer_id, recipient_id = '1', return_url = base_url + form_filled_type, user_name = signer_name, email = signer_email) results = envelope_api.create_recipient_view(account_id, envelope_id, recipient_view_request = recipient_view_request) return results.url
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... 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') document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Example document', # can be different from actual file name file_extension='pdf', # 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( # DocuSign SignHere field/tab document_id='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 testRequestASignature(self): with open(SignTest1File, 'rb') as sign_file: file_contents = sign_file.read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = Username signer.name = 'Pat Developer' signer.recipient_id = '1' # Create a SignHere tab somewhere on the document for the signer to sign sign_here = docusign.SignHere() sign_here.document_id = '1' sign_here.page_number = '1' sign_here.recipient_id = '1' sign_here.x_position = '100' sign_here.y_position = '100' sign_here.scale_value = '0.5' tabs = docusign.Tabs() tabs.sign_here_tabs = [sign_here] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients envelope_definition.status = 'sent' envelopes_api = EnvelopesApi() try: envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def send_template(self, name, email): webbrowser.open_new_tab(self._oauth_login_url) print(self._oauth_login_url) self._api_client.configure_jwt_authorization_flow( self._private_key_filename, self._oauth_base_url, self._integrator_key, self._user_id, 3600) docusign.configuration.api_client = self._api_client template_role_name = 'Needs to sign' # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # assign template information including ID and role(s) envelope_definition.template_id = self._template_id # create a template role with a valid template_id and role_name and assign signer info t_role = docusign.TemplateRole() t_role.role_name = template_role_name t_role.name = name t_role.email = email # create a list of template roles and add our newly created role # assign template role(s) to the envelope envelope_definition.template_roles = [t_role] # send the envelope by setting |status| to "sent". To save as a draft set to "created" envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login(api_password='******', include_account_id_guid='true') assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None self._base_url, _ = login_accounts[0].base_url.split('/v2') self._api_client.host = self._base_url docusign.configuration.api_client = api_client envelope_summary = envelopes_api.create_envelope(login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def get(self, request, *args, **kwargs): envelope_definition = make_envelope() envelopes_api = EnvelopesApi(get_api_client()) results = envelopes_api.create_envelope(ACCOUNT_ID, envelope_definition=envelope_definition) sign_envelope = SigEnvelope.objects.create(envelope_id=results.envelope_id) sign_request = SignRequest.objects.create(envelope=sign_envelope, error_details=results.error_details, status_date_time=results.status_date_time) Recipient.objects.create(recipient_id='1', sign_request=sign_request, email='*****@*****.**') return JsonResponse({'envelope_id': results.envelope_id})
def testRequestSignatureFromTemplate(self): template_role_name = 'Needs to sign' # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # assign template information including ID and role(s) envelope_definition.template_id = template_id # create a template role with a valid templateId and roleName and assign signer info t_role = docusign.TemplateRole() t_role.role_name = template_role_name t_role.name = 'Pat Developer' t_role.email = username # create a list of template roles and add our newly created role # assign template role(s) to the envelope envelope_definition.template_roles = [t_role] # send the envelope by setting |status| to "sent". To save as a draft set to "created" envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login(api_password='******', include_account_id_guid='true') assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') self.api_client.host = base_url docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def setUp(self): self.api_client = docusign.ApiClient(base_path=BaseUrl, oauth_host_name=OauthHostName) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client try: email_subject = 'Please Sign my Python SDK Envelope' email_blurb = 'Hello, Please sign my Python SDK Envelope.' template_id = TemplateId role_name = 'Needs to sign' name = 'Pat Developer' email = Username t_role = docusign.TemplateRole(role_name=role_name, name=name, email=email) # send the envelope by setting |status| to "sent". To save as a draft set to "created" status = 'sent' # create an envelope definition envelope_definition = docusign.EnvelopeDefinition( email_subject=email_subject, email_blurb=email_blurb, template_id=template_id, template_roles=[t_role], status=status) envelopes_api = EnvelopesApi() self.api_client.host = BaseUrl token = (self.api_client.request_jwt_user_token( client_id=IntegratorKey, user_id=UserId, oauth_host_name=OauthHostName, private_key_bytes=PrivateKeyBytes, expires_in=3600)) self.user_info = self.api_client.get_user_info(token.access_token) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) self.api_client.rest_client.pool_manager.clear() self.envelope_id = envelope_summary.envelope_id except ApiException as e: print("\nException when calling DocuSign API: %s" % e) except Exception as e: print("\nException when calling DocuSign API: %s" % e) self.api_client.rest_client.pool_manager.clear()
def send(cls, envelope): """Send an envelope Parameters: envelope (object): EnvelopeDefinition object Returns: envelope_id (str): envelope ID """ # Call Envelope API create method # Exceptions will be caught by the calling function ds_client = DsClient.get_instance() envelope_api = EnvelopesApi(ds_client.api_client) results = envelope_api.create_envelope(ds_client.account_id, envelope_definition=envelope) return results.envelope_id
def testRequestSignatureFromTemplate(self): template_role_name = 'Needs to sign' # Set properties and create an envelope later on email_subject = 'Please Sign my Python SDK Envelope' email_blurb = 'Hello, Please sign my Python SDK Envelope.' # assign template information including ID and role(s) template_id = TemplateId # create a template role with a valid templateId and roleName and assign signer info role_name = template_role_name name = 'Pat Developer' email = Username t_role = docusign.TemplateRole(role_name=role_name, name=name, email=email) # create a list of template roles and add our newly created role # assign template role(s) to the envelope template_roles = [t_role] # send the envelope by setting |status| to "sent". To save as a draft set to "created" status = 'sent' # create the envelope definition with the properties set envelope_definition = docusign.EnvelopeDefinition( email_subject=email_subject, email_blurb=email_blurb, template_id=template_id, template_roles=template_roles, status=status) envelopes_api = EnvelopesApi() try: envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def get(self, request, *args, **kwargs): api_client = get_api_client() bulk_envelopes_api = BulkEnvelopesApi(api_client) recipient_1 = BulkSendingCopyRecipient(role_name='signer', name='Aaqib 1', email='*****@*****.**') recipient_2 = BulkSendingCopyRecipient(role_name='signer', name='Aaqib 2', email='*****@*****.**') bulk_copies = [ BulkSendingCopy(recipients=[recipient_1], custom_fields=[]), BulkSendingCopy(recipients=[recipient_2], custom_fields=[]), ] bulk_sending_list = BulkSendingList(name='employee_contract', bulk_copies=bulk_copies) bulk_list = bulk_envelopes_api.create_bulk_send_list(ACCOUNT_ID, bulk_sending_list=bulk_sending_list) bulk_list_id = bulk_list.list_id envelopes_api = EnvelopesApi(api_client) with open(f'{BASE_DIR}/document.pdf', 'rb') as pdf_file: content_bytes = pdf_file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64=base64_file_content, name='Employee Contract', file_extension='pdf', document_id='1') envelope_definition = EnvelopeDefinition(email_subject='Please sign this document set', documents=[document], recipients={}, status='created', envelope_id_stamping='true') envelope = envelopes_api.create_envelope(account_id=ACCOUNT_ID, envelope_definition=envelope_definition) envelope_id = envelope.envelope_id text_custom_fields = TextCustomField(name='mailingListId', required='false', show='false', value=bulk_list_id) custom_fields = CustomFields(list_custom_fields=[], text_custom_fields=[text_custom_fields]) envelopes_api.create_custom_fields(account_id=ACCOUNT_ID, envelope_id=envelope_id, custom_fields=custom_fields) signer = Signer(name='Multi Bulk Recipient::signer', email='*****@*****.**', role_name='signer', note='', routing_order='1', status='created', delivery_method='email', recipient_id='13', recipient_type='signer') envelopes_api.create_recipient(ACCOUNT_ID, envelope_id, recipients=Recipients(signers=[signer])) bulk_send_request = BulkSendRequest(envelope_or_template_id=envelope_id) batch = bulk_envelopes_api.create_bulk_send_request(ACCOUNT_ID, bulk_list_id, bulk_send_request=bulk_send_request) time.sleep(10) from_date = (datetime.utcnow() - timedelta(seconds=60)).isoformat() envelopes = envelopes_api.list_status_changes(ACCOUNT_ID, status='sent', from_date=from_date).envelopes for envelope in envelopes: env, created = SigEnvelope.objects.get_or_create(envelope_id=envelope.envelope_id) if created: sign_request = SignRequest.objects.create(envelope=env, status_date_time=envelope.status_date_time) recipients = envelopes_api.list_recipients(ACCOUNT_ID, envelope.envelope_id) Recipient.objects.create(sign_request=sign_request, email=recipients.signers[0].email, recipient_id=recipients.signers[0].recipient_id) return redirect('esign:envelope_list')
def worker(cls, args): """ 1. Create the envelope request object 2. Send the envelope """ envelope_args = args["envelope_args"] # 1. Create the envelope request object envelope_definition = cls.make_envelope(envelope_args) # 2. call Envelopes::create API method # Exceptions will be caught by the calling function api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition) envelope_id = results.envelope_id return {"envelope_id": envelope_id}
def worker(cls, args): """ 1. Create an api client 2. Create an envelope definition object 3. Apply the brand to the envelope using the SDK """ # Step 2. Construct your API headers api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) # Step 3. Construct your request body envelope_api = EnvelopesApi(api_client) envelope_definition = cls.make_envelope(args["envelope_args"]) # Step 4. Call the eSignature REST API response = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition) return response
def setUp(self): self.api_client = docusign.ApiClient(base_path=BaseUrl, oauth_host_name=OauthHostName) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client self.private_key_file_name = "{}/keys/private.pem".format( os.path.dirname(os.path.abspath(__file__))) try: envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' envelope_definition.template_id = TemplateId t_role = docusign.TemplateRole() t_role.role_name = 'Needs to sign' t_role.name = 'Pat Developer' t_role.email = Username envelope_definition.template_roles = [t_role] # send the envelope by setting |status| to "sent". To save as a draft set to "created" envelope_definition.status = 'sent' envelopes_api = EnvelopesApi() with open(self.private_key_file_name, 'r') as private_key: self.api_client.host = BaseUrl token = (self.api_client.request_jwt_user_token( client_id=IntegratorKey, user_id=UserId, oauth_host_name=OauthHostName, private_key_bytes=private_key.read(), expires_in=1)) self.user_info = self.api_client.get_user_info(token.access_token) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) self.api_client.rest_client.pool_manager.clear() self.envelope_id = envelope_summary.envelope_id except ApiException as e: print("\nException when calling DocuSign API: %s" % e) self.api_client.rest_client.pool_manager.clear()
def worker(cls, args): """ Create the envelope and the embedded Signing Ceremony 1. Create the envelope request object using composite template to add the new document 2. Send the envelope 3. Make the recipient view request object 4. Get the recipient view (Signing Ceremony) url """ envelope_args = args["envelope_args"] # 1. Create the envelope request object envelope_definition = cls.make_envelope(envelope_args) # 2. call Envelopes::create API method # Exceptions will be caught by the calling function api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( account_id=args["account_id"], envelope_definition=envelope_definition) envelope_id = results.envelope_id # 3. Create the Recipient View request object authentication_method = "None" # How is this application authenticating # the signer? See the "authenticationMethod" definition # https://goo.gl/qUhGTm recipient_view_request = RecipientViewRequest( authentication_method=authentication_method, client_user_id=envelope_args["signer_client_id"], recipient_id="1", return_url=envelope_args["ds_return_url"], user_name=envelope_args["signer_name"], email=envelope_args["signer_email"]) # 4. Obtain the recipient_view_url for the signing ceremony # Exceptions will be caught by the calling function results = envelope_api.create_recipient_view( account_id=args["account_id"], envelope_id=envelope_id, recipient_view_request=recipient_view_request) return {"envelope_id": envelope_id, "redirect_url": results.url}
def send(envelope, session): """Send an envelope Parameters: envelope (object): EnvelopeDefinition object Returns: envelope_id (str): envelope ID """ # Call Envelope API create method # Exceptions will be caught by the calling function access_token = session.get('access_token') account_id = session.get('account_id') ds_client = DsClient.get_configured_instance(access_token) envelope_api = EnvelopesApi(ds_client) results = envelope_api.create_envelope( account_id, envelope_definition=envelope ) return results.envelope_id
def worker(cls, args): """ 1. Create the envelope request object 2. Send the envelope 3. Create the Recipient View request object 4. Obtain the recipient_view_url for the signing ceremony """ envelope_args = args["envelope_args"] # 1. Create the envelope request object envelope_definition = cls.make_envelope(envelope_args) # 2. call Envelopes::create API method # Exceptions will be caught by the calling function api_client = create_api_client( base_path=args["base_path"], access_token=args["access_token"] ) envelopes_api = EnvelopesApi(api_client) results = envelopes_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition) envelope_id = results.envelope_id app.logger.info(f"Envelope was created. EnvelopeId {envelope_id}") # 3. Create the RecipientViewRequest object recipient_view_request = RecipientViewRequest( authentication_method=authentication_method, client_user_id=envelope_args["signer_client_id"], recipient_id="1", return_url=envelope_args["ds_return_url"], user_name=envelope_args["signer_name"], email=envelope_args["signer_email"] ) # 4. Obtain the recipient view URL for the signing ceremony # Exceptions will be caught by the calling function results = envelopes_api.create_recipient_view( account_id=args["account_id"], envelope_id=envelope_id, recipient_view_request=recipient_view_request ) return {"envelope_id": envelope_id, "redirect_url": results.url}
def testMoveEnvelopes(self): with open(SignTest1File, 'rb') as sign_file: file_contents = sign_file.read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = Username signer.name = 'Pat Developer' signer.recipient_id = '1' # Create a SignHere tab somewhere on the document for the signer to sign sign_here = docusign.SignHere() sign_here.document_id = '1' sign_here.page_number = '1' sign_here.recipient_id = '1' sign_here.x_position = '100' sign_here.y_position = '100' sign_here.scale_value = '0.5' tabs = docusign.Tabs() tabs.sign_here_tabs = [sign_here] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients envelope_definition.status = 'sent' envelopes_api = EnvelopesApi() try: envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' folders_api = FoldersApi() folders_request = docusign.FoldersRequest( envelope_ids=[envelope_summary.envelope_id], from_folder_id="sentitems") to_folder_id = "draft" folders_api.move_envelopes(self.user_info.accounts[0].account_id, to_folder_id, folders_request=folders_request) # Wait for 1 second to make sure the newly created envelope was moved to the 'sentitems' folder # Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id # In production, use DocuSign Connect to get notified when the status of the envelope have changed. sleep(1) # Test if we moved the envelope to the correct folder list_from_drafts_folder = folders_api.list_items( self.user_info.accounts[0].account_id, to_folder_id) assert list_from_drafts_folder is not None for item in list_from_drafts_folder.folder_items: if item.envelope_id == envelope_summary.envelope_id: return assert False except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def testGetDiagnosticLogs(self): with open(SignTest1File, 'rb') as sign_file: file_contents = sign_file.read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = Username signer.name = 'Pat Developer' signer.recipient_id = '1' # this value represents the client's unique identifier for the signer client_user_id = '2939' signer.client_user_id = client_user_id # Create a SignHere tab somewhere on the document for the signer to sign sign_here = docusign.SignHere() sign_here.document_id = '1' sign_here.page_number = '1' sign_here.recipient_id = '1' sign_here.x_position = '100' sign_here.y_position = '100' sign_here.scale_value = '0.5' tabs = docusign.Tabs() tabs.sign_here_tabs = [sign_here] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients # send the envelope (otherwise it will be "created" in the Draft folder) envelope_definition.status = 'sent' envelopes_api = EnvelopesApi() diag_api = DiagnosticsApi() try: docusign.configuration.api_client = self.api_client diagnostics_settings_information = docusign.DiagnosticsSettingsInformation( ) diagnostics_settings_information.api_request_logging = 'true' diag_api.update_request_log_settings( diagnostics_settings_information= diagnostics_settings_information) envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) envelope_id = envelope_summary.envelope_id file1 = envelopes_api.get_document( self.user_info.accounts[0].account_id, 'combined', envelope_id) assert len(file1) > 0 subprocess.call('open ' + file1, shell=True) logs_list = diag_api.list_request_logs() request_log_id = logs_list.api_request_logs[0].request_log_id file2 = diag_api.get_request_log(request_log_id) assert len(file2) > 0 subprocess.call('open ' + file2, shell=True) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def testEmbeddedSigning(self): with open(SignTest1File, 'rb') as sign_file: file_contents = sign_file.read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = Username signer.name = 'Pat Developer' signer.recipient_id = '1' # this value represents the client's unique identifier for the signer client_user_id = '2939' signer.client_user_id = client_user_id # Create a SignHere tab somewhere on the document for the signer to sign sign_here = docusign.SignHere() sign_here.document_id = '1' sign_here.page_number = '1' sign_here.recipient_id = '1' sign_here.x_position = '100' sign_here.y_position = '100' sign_here.scale_value = '0.5' tabs = docusign.Tabs() tabs.sign_here_tabs = [sign_here] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients envelope_definition.status = 'sent' envelopes_api = EnvelopesApi() try: return_url = 'http://www.docusign.com/developer-center' recipient_view_request = docusign.RecipientViewRequest() recipient_view_request.return_url = return_url recipient_view_request.client_user_id = client_user_id recipient_view_request.authentication_method = 'email' recipient_view_request.user_name = 'Pat Developer' recipient_view_request.email = Username envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) envelope_id = envelope_summary.envelope_id view_url = envelopes_api.create_recipient_view( self.user_info.accounts[0].account_id, envelope_id, recipient_view_request=recipient_view_request) assert view_url is not None assert view_url.url is not None # This Url should work in an Iframe or browser to allow signing print("ViewUrl is ", end="") pprint(view_url) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
envelopes_api = EnvelopesApi() try: #region get base_url login_info = auth_api.login( api_password='******', include_account_id_guid='true' ) #NOTE that we have a hack here to bypass the error ref. https://github.com/docusign/docusign-python-client/issues/10 assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') #endregion get base_url #region send email to sign api_client.host = base_url docusign.configuration.api_client = api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("envelope_summary=") pprint(envelope_summary) #endregion except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def testResendEnvelope(self): file_contents = open(sign_test1_file, 'rb').read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = username signer.name = 'Pat Developer' signer.recipient_id = '1' # this value represents the client's unique identifier for the signer client_user_id = '2939' signer.client_user_id = client_user_id # Create a SignHere tab somewhere on the document for the signer to sign sign_here = docusign.SignHere() sign_here.document_id = '1' sign_here.page_number = '1' sign_here.recipient_id = '1' sign_here.x_position = '100' sign_here.y_position = '100' sign_here.scale_value = '0.5' tabs = docusign.Tabs() tabs.sign_here_tabs = [sign_here] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients # send the envelope (otherwise it will be "created" in the Draft folder) envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login() assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') self.api_client.host = base_url docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None print("EnvelopeSummary: ", end="") pprint(envelope_summary) recipients_update_summary = envelopes_api.update_recipients( login_accounts[0].account_id, envelope_summary.envelope_id, recipients=recipients, resend_envelope='true') assert recipients_update_summary is not None assert len(recipients_update_summary.recipient_update_results) > 0 assert ("SUCCESS" == recipients_update_summary. recipient_update_results[0].error_details.error_code) print("RecipientsUpdateSummary: ", end="") pprint(recipients_update_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def testDownLoadEnvelopeDocuments(self): file_contents = open(sign_test1_file, 'rb').read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = username signer.name = 'Pat Developer' signer.recipient_id = '1' # this value represents the client's unique identifier for the signer client_user_id = '2939' signer.client_user_id = client_user_id # Create a Text tab somewhere on the document for the signer to sign text = docusign.Text() text.document_id = '1' text.page_number = '1' text.recipient_id = '1' text.x_position = '100' text.y_position = '100' text.scale_value = '0.5' tabs = docusign.Tabs() tabs.text_tabs = [text] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients # send the envelope (otherwise it will be "created" in the Draft folder) envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login() assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') self.api_client.host = base_url docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None print("EnvelopeSummary: ", end="") pprint(envelope_summary) file = envelopes_api.get_document(login_accounts[0].account_id, 'combined', envelope_summary.envelope_id) assert len(file) > 0 subprocess.call('open ' + file, shell=True) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def testRequestASignature(self): file_contents = open(sign_test1_file, 'rb').read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = 'TestFile.pdf' doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = username signer.name = 'Pat Developer' signer.recipient_id = '1' # Create a SignHere tab somewhere on the document for the signer to sign sign_here = docusign.SignHere() sign_here.document_id = '1' sign_here.page_number = '1' sign_here.recipient_id = '1' sign_here.x_position = '100' sign_here.y_position = '100' sign_here.scale_value = '0.5' tabs = docusign.Tabs() tabs.sign_here_tabs = [sign_here] signer.tabs = tabs recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login(api_password='******', include_account_id_guid='true') assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') self.api_client.host = base_url docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def embedded_signing_ceremony(): """ The document <file_name> will be signed by <signer_name> via an embedded signing ceremony. """ # # Step 1. The envelope definition is created. # One signHere tab is added. # The document path supplied is relative to the working directory # envDef = EnvelopeDefinition() envDef.email_subject = 'PLEASE GOD HELP ME, I NEED THIS WORKING!!' envDef.template_id = 'd5e617be-da0a-4431-9014-4575282f61d4' tRole = TemplateRole() tRole.role_name = 'Manager' tRole.name = 'Manuel Galvez' tRole.email = '*****@*****.**' tRole.client_user_id = clientUserId text_example = Text() text_example.tab_label = 'example' text_example.value = 'SIIII GRACIAS DIOS!! -- EXAMPLE' text_name = Text() text_name.tab_label = 'name' text_name.value = 'SIIII GRACIAS DIOS!! -- NAME' # text.document_id = '1' # text.page_number = '1' # text.recipient_id = '1' # text.x_position = '100' # text.y_position = '100' # text.scale_value = '0.5' tabs = Tabs() tabs.text_tabs = [text_example, text_name] tRole.tabs = tabs # Tabs(text_tabs=[Text(name='example', value='SIiiiiiii Gracias DIOS')]) envDef.template_roles = [tRole] name = TextCustomField(field_id='name', name='name', value='Manuel') last_name = TextCustomField(field_id='lastname', name='lastname', value='Galvez') testing = TextCustomField(field_id='testing', name='testing', value='Elks') manu = TextCustomField(field_id='manu', name='manu', value='manu') example = TextCustomField(field_id='example', name='example', value='Siiiiiiii') custom_fields = CustomFields( text_custom_fields=[example, name, last_name, testing, manu]) envDef.custom_fields = custom_fields '''recipients = Recipients() # Create the signer recipient model signer = Signer( # The signer email='*****@*****.**', name='Andres Vasquez', recipient_id="1", routing_order="1", client_user_id=clientUserId, # Setting the client_user_id marks the signer as embedded ) text = Text() text.document_id = '1' text.page_number = '1' text.recipient_id = '1' text.x_position = '100' text.y_position = '100' text.scale_value = '0.5' tabs = Tabs() tabs.text_tabs = [text] signer.tabs = tabs recipients.signers = [signer] envDef.recipients = recipients''' envDef.status = 'sent' api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) envelope_api = EnvelopesApi(api_client) envelopeSummary = envelope_api.create_envelope(account_id, envelope_definition=envDef) envelope_id = envelopeSummary.envelope_id print("Envelope {} has been sent to {} : {}".format( envelope_id, tRole.email, envelopeSummary)) '''recipient_view_request = RecipientViewRequest( authentication_method='None', client_user_id=clientUserId, recipient_id='1', return_url=base_url + '/dsreturn', user_name='Andres Vasquez', email='*****@*****.**' ) results = envelope_api.create_recipient_view(account_id, envelope_id, recipient_view_request=recipient_view_request)''' return '' #results.url
def embedded_signing_ceremony(): """ The document <file_name> will be signed by <signer_name> via an embedded signing ceremony. """ # # Step 1. The envelope definition is created. # One signHere tab is added. # The document path supplied is relative to the working directory # # 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') document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Example document', # can be different from actual file name file_extension='pdf', # 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", client_user_id= client_user_id, # Setting the client_user_id marks the signer as embedded ) sign_here = SignHere( # DocuSign SignHere field/tab document_id='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. ) # # Step 2. Create/send the envelope. # 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) # # Step 3. The envelope has been created. # Request a Recipient View URL (the Signing Ceremony URL) # envelope_id = results.envelope_id recipient_view_request = RecipientViewRequest( authentication_method=authentication_method, client_user_id=client_user_id, recipient_id='1', return_url=base_url + '/dsreturn', user_name=signer_name, email=signer_email) results = envelope_api.create_recipient_view( account_id, envelope_id, recipient_view_request=recipient_view_request) # # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received. # Redirect the user's browser to it. # return results.url
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_email} name=args["envelope_args"]["signer_name"], # represents your {signer_name} phone_authentication={"senderProvidedNumbers": [args["envelope_args"]["phone_number"]]}, id_check_configuration_name="Phone Auth $", require_id_lookup="true", 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 testMoveEnvelopes(self): with open(SignTest1File, 'rb') as sign_file: file_contents = sign_file.read() # Set properties for envelope and create an envelope to be signed later on email_subject = 'Please Sign my Python SDK Envelope' email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope base64_doc = base64.b64encode(file_contents).decode("utf-8") name = 'TestFile.pdf' document_id = '1' doc = docusign.Document(document_base64=base64_doc, name=name, document_id=document_id) documents = [doc] # Add a recipient to sign the document email = Username name = 'Pat Developer' recipient_id = '1' signer = docusign.Signer(email=email, name=name, recipient_id=recipient_id) # Create a SignHere tab somewhere on the document for the signer to sign document_id = '1' page_number = '1' recipient_id = '1' x_position = '100' y_position = '100' scale_value = '0.5' sign_here = docusign.SignHere(document_id=document_id, page_number=page_number, recipient_id=recipient_id, x_position=x_position, y_position=y_position, scale_value=scale_value) sign_here_tabs = [sign_here] tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs) signer.tabs = tabs signers = [signer] recipients = docusign.Recipients(signers=signers) status = 'sent' # Now setting all the properties in previous steps create the envelope now envelope_definition = docusign.EnvelopeDefinition( email_subject=email_subject, email_blurb=email_blurb, documents=documents, recipients=recipients, status=status) envelopes_api = EnvelopesApi() try: envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' folders_api = FoldersApi() folders_request = docusign.FoldersRequest( envelope_ids=[envelope_summary.envelope_id], from_folder_id="sentitems") to_folder_id = "draft" folders_api.move_envelopes(self.user_info.accounts[0].account_id, to_folder_id, folders_request=folders_request) # Wait for 3 second to make sure the newly created envelope was moved to the 'sentitems' folder # Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id # In production, use DocuSign Connect to get notified when the status of the envelope have changed. # 3 Seconds because sometimes when not in public or slow networks, the call takes more time and fails for 1 second. sleep(3) # Test if we moved the envelope to the correct folder search_options = "true" list_from_drafts_folder = folders_api.list_items( self.user_info.accounts[0].account_id, to_folder_id, include_items=search_options) assert list_from_drafts_folder is not None for folder in list_from_drafts_folder.folders: for list_item in folder.folder_items: if list_item.envelope_id == envelope_summary.envelope_id: return assert False except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception