Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
87 changes: 74 additions & 13 deletions hellosign_sdk/hsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def send_signature_request(self, test_mode=False, client_id=None, files=None, fi
title=None, subject=None, message=None, signing_redirect_url=None,
signers=None, cc_email_addresses=None, form_fields_per_document=None,
use_text_tags=False, hide_text_tags=False, custom_fields=None,
metadata=None, allow_decline=False, allow_reassign=False, signing_options=None):
metadata=None, allow_decline=False, allow_reassign=False, signing_options=None, attachments=None):
''' Creates and sends a new SignatureRequest with the submitted documents

Creates and sends a new SignatureRequest with the submitted documents.
Expand Down Expand Up @@ -409,6 +409,12 @@ def send_signature_request(self, test_mode=False, client_id=None, files=None, fi

signing_options (dict, optional): Allows the requester to specify the types allowed for creating a signature. Defaults to account settings.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of the attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The index of the signer who needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded

Returns:
A SignatureRequest object

Expand Down Expand Up @@ -440,7 +446,8 @@ def send_signature_request(self, test_mode=False, client_id=None, files=None, fi
'metadata': metadata,
'allow_decline': allow_decline,
'allow_reassign': allow_reassign,
'signing_options': signing_options
'signing_options': signing_options,
'attachments': attachments
}

return self._send_signature_request(**params)
Expand Down Expand Up @@ -620,7 +627,7 @@ def send_signature_request_embedded(self, test_mode=False, client_id=None,
files=None, file_urls=None, title=None, subject=None, message=None,
signing_redirect_url=None, signers=None, cc_email_addresses=None,
form_fields_per_document=None, use_text_tags=False, hide_text_tags=False,
metadata=None, allow_decline=False, allow_reassign=False, signing_options=None):
metadata=None, allow_decline=False, allow_reassign=False, signing_options=None, attachments=None):
''' Creates and sends a new SignatureRequest with the submitted documents

Creates a new SignatureRequest with the submitted documents to be signed
Expand Down Expand Up @@ -674,6 +681,13 @@ def send_signature_request_embedded(self, test_mode=False, client_id=None,

signing_options (dict, optional): Allows the requester to specify the types allowed for creating a signature. Defaults to account settings.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The signer's index whose needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded


Returns:
A SignatureRequest object

Expand Down Expand Up @@ -706,7 +720,8 @@ def send_signature_request_embedded(self, test_mode=False, client_id=None,
'allow_decline': allow_decline,
'allow_reassign': allow_reassign,
'signing_options': signing_options,
'is_for_embedded_signing': True
'is_for_embedded_signing': True,
'attachments': attachments
}

return self._send_signature_request(**params)
Expand Down Expand Up @@ -977,7 +992,7 @@ def update_template_files(self, template_id, files=None, file_urls=None,
def create_embedded_template_draft(self, client_id, signer_roles, test_mode=False,
files=None, file_urls=None, title=None, subject=None, message=None,
cc_roles=None, merge_fields=None, skip_me_now=False, use_preexisting_fields=False,
allow_reassign=False, metadata=None, allow_ccs=False):
allow_reassign=False, metadata=None, allow_ccs=False, attachments=None):
''' Creates an embedded Template draft for further editing.

Args:
Expand Down Expand Up @@ -1024,6 +1039,12 @@ def create_embedded_template_draft(self, client_id, signer_roles, test_mode=Fals
allow_ccs (bool, optional): Specifies whether the user is allowed to
provide email addresses to CC when creating a template. Defaults to False.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of the attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The index of the signer who needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded

Returns:
A Template object specifying the id of the draft

Expand All @@ -1043,7 +1064,8 @@ def create_embedded_template_draft(self, client_id, signer_roles, test_mode=Fals
'use_preexisting_fields': use_preexisting_fields,
'metadata': metadata,
'allow_reassign': allow_reassign,
'allow_ccs': allow_ccs
'allow_ccs': allow_ccs,
'attachments': attachments
}

return self._create_embedded_template_draft(**params)
Expand Down Expand Up @@ -1381,7 +1403,7 @@ def create_unclaimed_draft(self, test_mode=False, files=None, file_urls=None,
draft_type=None, subject=None, message=None, signers=None, custom_fields=None,
cc_email_addresses=None, signing_redirect_url=None, form_fields_per_document=None,
metadata=None, use_preexisting_fields=False, use_text_tags=False,
hide_text_tags=False, allow_decline=False, signing_options=None):
hide_text_tags=False, allow_decline=False, signing_options=None, attachments=None):
''' Creates a new Draft that can be claimed using the claim URL

Creates a new Draft that can be claimed using the claim URL. The first
Expand Down Expand Up @@ -1437,6 +1459,12 @@ def create_unclaimed_draft(self, test_mode=False, files=None, file_urls=None,
signing_options (dict, optional): Allows the requester to specify the types allowed for creating a signature.
Defaults to account settings.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of the attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The index of the signer who needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded

Returns:
An UnclaimedDraft object

Expand Down Expand Up @@ -1467,7 +1495,8 @@ def create_unclaimed_draft(self, test_mode=False, files=None, file_urls=None,
'use_text_tags': use_text_tags,
'hide_text_tags': hide_text_tags,
'allow_decline': allow_decline,
'signing_options': signing_options
'signing_options': signing_options,
'attachments': attachments
}

return self._create_unclaimed_draft(**params)
Expand All @@ -1479,7 +1508,7 @@ def create_embedded_unclaimed_draft(self, test_mode=False, client_id=None,
requesting_redirect_url=None, form_fields_per_document=None, metadata=None,
use_preexisting_fields=False, use_text_tags=False, hide_text_tags=False,
skip_me_now=False, allow_decline=False, allow_reassign=False,
signing_options=None, allow_ccs=False):
signing_options=None, allow_ccs=False, attachments=None):
''' Creates a new Draft to be used for embedded requesting

Args:
Expand Down Expand Up @@ -1534,6 +1563,12 @@ def create_embedded_unclaimed_draft(self, test_mode=False, client_id=None,

allow_ccs (bool, optional): Specifies whether the user is allowed to provide email addresses to CC when sending the request. Defaults to False.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of the attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The index of the signer who needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded

Returns:
An UnclaimedDraft object

Expand Down Expand Up @@ -1573,7 +1608,8 @@ def create_embedded_unclaimed_draft(self, test_mode=False, client_id=None,
'signing_options': signing_options,
'allow_reassign': allow_reassign,
'allow_decline': allow_decline,
'allow_ccs': allow_ccs
'allow_ccs': allow_ccs,
'attachments': attachments
}

return self._create_unclaimed_draft(**params)
Expand Down Expand Up @@ -1857,7 +1893,7 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,
signing_redirect_url=None, signers=None, custom_fields=None,
cc_email_addresses=None, form_fields_per_document=None, use_text_tags=False,
hide_text_tags=False, metadata=None, allow_decline=False, allow_reassign=False,
signing_options=None, is_for_embedded_signing=False):
signing_options=None, is_for_embedded_signing=False, attachments=None):
''' To share the same logic between send_signature_request &
send_signature_request_embedded functions

Expand Down Expand Up @@ -1906,6 +1942,13 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,

is_for_embedded_signing (bool): send_signature_request and send_signature_request_embedded share the same sending logic. To differenciate the two calls embedded requests are now flagged.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The signer's index whose needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded


Returns:
A SignatureRequest object

Expand All @@ -1932,6 +1975,9 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,
# Signing options
signing_options_payload = HSFormat.format_signing_options(signing_options, 'signing_options')

# Attachments
attachments_payload = HSFormat.format_dict_list(attachments, 'attachments')

payload = {
"test_mode": self._boolean(test_mode),
"client_id": client_id,
Expand Down Expand Up @@ -1961,6 +2007,7 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,
data.update(file_urls_payload)
data.update(metadata_payload)
data.update(signing_options_payload)
data.update(attachments_payload)

request = self._get_request()
response = request.post(url, data=data, files=files_payload)
Expand Down Expand Up @@ -2088,7 +2135,7 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,
requesting_redirect_url=None, form_fields_per_document=None, metadata=None,
use_preexisting_fields=False, use_text_tags=False, hide_text_tags=False,
skip_me_now=False, allow_reassign=False, allow_decline=False,
signing_options=None, allow_ccs=False):
signing_options=None, allow_ccs=False, attachments=None):
''' Creates a new Draft that can be claimed using the claim URL

Args:
Expand Down Expand Up @@ -2145,6 +2192,12 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,

allow_ccs (bool, optional): Specifies whether the user is allowed to provide email addresses to CC when sending the request. Defaults to False.

attachments (list of dict): A list of attachments, each with the following attributes:
name (str): The name of the attachment
instructions (str): The instructions for uploading the attachment
signer_index (int): The index of the signer who needs to upload the attachments, see signers parameter for more details
required (bool, optional): Determines if the attachment must be uploaded

Returns:
An UnclaimedDraft object

Expand Down Expand Up @@ -2177,6 +2230,9 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,
# Signing options
signing_options_payload = HSFormat.format_signing_options(signing_options, 'signing_options')

# Attachments
attachments_payload = HSFormat.format_dict_list(attachments, 'attachments')

payload = {
"test_mode": self._boolean(test_mode),
"type": draft_type,
Expand Down Expand Up @@ -2214,6 +2270,7 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,
data.update(file_urls_payload)
data.update(metadata_payload)
data.update(signing_options_payload)
data.update(attachments_payload)

request = self._get_request()
response = request.post(url, data=data, files=files_payload)
Expand Down Expand Up @@ -2300,7 +2357,7 @@ def _add_remove_team_member(self, url, email_address=None, account_id=None):
def _create_embedded_template_draft(self, client_id, signer_roles, test_mode=False,
files=None, file_urls=None, title=None, subject=None, message=None,
cc_roles=None, merge_fields=None, skip_me_now=False,
use_preexisting_fields=False, metadata=None, allow_reassign=False, allow_ccs=False):
use_preexisting_fields=False, metadata=None, allow_reassign=False, allow_ccs=False, attachments=None):
''' Helper method for creating embedded template drafts.
See public function for params.
'''
Expand Down Expand Up @@ -2335,6 +2392,9 @@ def _create_embedded_template_draft(self, client_id, signer_roles, test_mode=Fal
# Prep Metadata
metadata_payload = HSFormat.format_single_dict(metadata, 'metadata')

# Attachments
attachments_payload = HSFormat.format_dict_list(attachments, 'attachments')

# Assemble data for sending
data = {}
data.update(payload)
Expand All @@ -2345,6 +2405,7 @@ def _create_embedded_template_draft(self, client_id, signer_roles, test_mode=Fal
if (merge_fields is not None):
data.update(merge_fields_payload)
data = HSFormat.strip_none_values(data)
data.update(attachments_payload)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this line with the rest of the updates above.


request = self._get_request()

Expand Down