This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
hsclient.py
1793 lines (1254 loc) · 75.3 KB
/
hsclient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from hellosign_sdk.utils import HSRequest, HSException, NoAuthMethod, HSAccessTokenAuth, HSFormat, api_resource, api_resource_list
from hellosign_sdk.resource import Account, SignatureRequest, Template, Team, Embedded, UnclaimedDraft
from requests.auth import HTTPBasicAuth
import json
#
# The MIT License (MIT)
#
# Copyright (C) 2014 hellosign.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
class HSClient(object):
''' Client object to interact with the API urls
Most of the operations of the SDK is made through this object. Please refer
to the README.rst file for more details on how to use the client object.
'''
version = '3.8.5' # SDK version
API_VERSION = 'v3' # API version
API_URL = ''
ACCOUNT_CREATE_URL = ''
ACCOUNT_INFO_URL = ''
ACCOUNT_UPDATE_URL = ''
ACCOUNT_VERIFY_URL = ''
SIGNATURE_REQUEST_INFO_URL = ''
SIGNATURE_REQUEST_LIST_URL = ''
SIGNATURE_REQUEST_DOWNLOAD_PDF_URL = ''
SIGNATURE_REQUEST_CREATE_URL = ''
SIGNATURE_REQUEST_CREATE_WITH_TEMPLATE_URL = ''
SIGNATURE_REQUEST_REMIND_URL = ''
SIGNATURE_REQUEST_CANCEL_URL = ''
SIGNATURE_REQUEST_CREATE_EMBEDDED_URL = ''
SIGNATURE_REQUEST_CREATE_EMBEDDED_WITH_TEMPLATE_URL = ''
EMBEDDED_OBJECT_GET_URL = ''
EMBEDDED_TEMPLATE_EDIT_URL = ''
UNCLAIMED_DRAFT_CREATE_URL = ''
UNCLAIMED_DRAFT_CREATE_EMBEDDED_URL = ''
UNCLAIMED_DRAFT_CREATE_EMBEDDED_WITH_TEMPLATE_URL = ''
TEMPLATE_GET_URL = ''
TEMPLATE_GET_LIST_URL = ''
TEMPLATE_GET_FILES_URL = ''
TEMPLATE_DELETE_URL = ''
TEMPLATE_ADD_USER_URL = ''
TEMPLATE_REMOVE_USER_URL = ''
TEMPLATE_CREATE_EMBEDDED_DRAFT_URL = ''
TEAM_INFO_URL = ''
TEAM_UPDATE_URL = ''
TEAM_CREATE_URL = ''
TEAM_DESTROY_URL = ''
TEAM_ADD_MEMBER_URL = ''
TEAM_REMOVE_MEMBER_URL = ''
OAUTH_TOKEN_URL = ''
request = None
response_callback = None
def __init__(self, email_address=None, password=None, api_key=None, access_token=None, access_token_type="Bearer", env='production'):
'''Initialize the client object with authentication information to send requests
Args:
email_address (str): E-mail of the account to make the requests
password (str): Password of the account used with email address
api_key (str): API Key. You can find your API key in https://www.hellosign.com/home/myAccount/current_tab/integrations
access_token (str): OAuth access token to use
access_token_type (str): Type of OAuth token (defaults to Bearer, which is the only value supported for now)
'''
super(HSClient, self).__init__()
self.auth = self._authenticate(email_address, password, api_key, access_token, access_token_type)
self.account = Account()
self.env = env
self._init_endpoints()
def __str__(self):
''' Return a string description of this object '''
return "HelloSign Client %s" % self.version
def _init_endpoints(self):
API_PRODUCTION_URL = "https://api.hellosign.com"
API_DEV_URL = "https://www.dev-hellosign.com/apiapp_dev.php"
API_STAGING_URL = "https://staging.hellosign.com/apiapp.php"
WEB_PRODUCTION_URL = "https://www.hellosign.com"
WEB_DEV_URL = "https://www.dev-hellosign.com/webapp_dev.php"
WEB_STAGING_URL = "https://staging.hellosign.com/webapp_dev.php"
if self.env == "production":
self.API_URL = API_PRODUCTION_URL + '/' + self.API_VERSION
self.OAUTH_TOKEN_URL = WEB_PRODUCTION_URL + '/oauth/token'
elif self.env == "dev":
self.API_URL = API_DEV_URL + '/' + self.API_VERSION
self.OAUTH_TOKEN_URL = WEB_DEV_URL + '/oauth/token'
print("WARNING: Using dev api endpoint %s" % self.API_URL)
elif self.env == "staging":
self.API_URL = API_STAGING_URL + '/' + self.API_VERSION
self.OAUTH_TOKEN_URL = WEB_STAGING_URL + '/oauth/token'
print("WARNING: Using staging api endpoint %s" % self.API_URL)
self.ACCOUNT_CREATE_URL = self.API_URL + '/account/create'
self.ACCOUNT_INFO_URL = self.API_URL + '/account'
self.ACCOUNT_UPDATE_URL = self.API_URL + '/account'
self.ACCOUNT_VERIFY_URL = self.API_URL + '/account/verify'
self.SIGNATURE_REQUEST_INFO_URL = self.API_URL + '/signature_request/'
self.SIGNATURE_REQUEST_LIST_URL = self.API_URL + '/signature_request/list'
self.SIGNATURE_REQUEST_DOWNLOAD_PDF_URL = self.API_URL + '/signature_request/files/'
self.SIGNATURE_REQUEST_CREATE_URL = self.API_URL + '/signature_request/send'
self.SIGNATURE_REQUEST_CREATE_WITH_TEMPLATE_URL = self.API_URL + '/signature_request/send_with_template'
self.SIGNATURE_REQUEST_REMIND_URL = self.API_URL + '/signature_request/remind/'
self.SIGNATURE_REQUEST_CANCEL_URL = self.API_URL + '/signature_request/cancel/'
self.SIGNATURE_REQUEST_CREATE_EMBEDDED_URL = self.API_URL + '/signature_request/create_embedded'
self.SIGNATURE_REQUEST_CREATE_EMBEDDED_WITH_TEMPLATE_URL = self.API_URL + '/signature_request/create_embedded_with_template'
self.EMBEDDED_OBJECT_GET_URL = self.API_URL + '/embedded/sign_url/'
self.EMBEDDED_TEMPLATE_EDIT_URL = self.API_URL + '/embedded/edit_url/'
self.UNCLAIMED_DRAFT_CREATE_URL = self.API_URL + '/unclaimed_draft/create'
self.UNCLAIMED_DRAFT_CREATE_EMBEDDED_URL = self.API_URL + '/unclaimed_draft/create_embedded'
self.UNCLAIMED_DRAFT_CREATE_EMBEDDED_WITH_TEMPLATE_URL = self.API_URL + '/unclaimed_draft/create_embedded_with_template'
self.TEMPLATE_GET_URL = self.API_URL + '/template/'
self.TEMPLATE_GET_LIST_URL = self.API_URL + '/template/list'
self.TEMPLATE_GET_FILES_URL = self.API_URL + '/template/files/'
self.TEMPLATE_DELETE_URL = self.API_URL + '/template/delete/'
self.TEMPLATE_ADD_USER_URL = self.API_URL + '/template/add_user/'
self.TEMPLATE_REMOVE_USER_URL = self.API_URL + '/template/remove_user/'
self.TEMPLATE_CREATE_EMBEDDED_DRAFT_URL = self.API_URL + '/template/create_embedded_draft'
self.TEAM_INFO_URL = self.API_URL + '/team'
self.TEAM_UPDATE_URL = self.TEAM_INFO_URL
self.TEAM_CREATE_URL = self.API_URL + '/team/create'
self.TEAM_DESTROY_URL = self.API_URL + '/team/destroy'
self.TEAM_ADD_MEMBER_URL = self.API_URL + '/team/add_member'
self.TEAM_REMOVE_MEMBER_URL = self.API_URL + '/team/remove_member'
# ---- ACCOUNT METHODS -----------------------------
@api_resource(Account)
def create_account(self, email_address, password=None, client_id=None, client_secret=None):
''' Create a new account.
If the account is created via an app, then Account.oauth will contain the
OAuth data that can be used to execute actions on behalf of the newly created account.
Args:
email_address (str): Email address of the new account to create
password (str): [DEPRECATED] This parameter will be ignored
client_id (str, optional): Client id of the app to use to create this account
client_secret (str, optional): Secret of the app to use to create this account
Returns:
The new Account object
'''
request = self._get_request()
params = {
'email_address': email_address
}
if client_id:
params['client_id'] = client_id
params['client_secret'] = client_secret
response = request.post(self.ACCOUNT_CREATE_URL, params)
if 'oauth_data' in response:
response["account"]["oauth"] = response['oauth_data']
return response
# Get account info and put in self.account so that further access to the
# info can be made by using self.account.attribute
def get_account_info(self):
''' Get current account information
The information then will be saved in `self.account` so that you can
access the information like this:
>>> hsclient = HSClient()
>>> acct = hsclient.get_account_info()
>>> print acct.email_address
Returns:
An Account object
'''
request = self._get_request()
response = request.get(self.ACCOUNT_INFO_URL)
self.account.json_data = response["account"]
return self.account
# At the moment you can only update your callback_url only
@api_resource(Account)
def update_account_info(self):
''' Update current account information
At the moment you can only update your callback_url.
Returns:
An Account object
'''
request = self._get_request()
return request.post(self.ACCOUNT_UPDATE_URL, {
'callback_url': self.account.callback_url
})
def verify_account(self, email_address):
''' Verify whether a HelloSign Account exists
Args:
email_address (str): Email address for the account to verify
Returns:
True or False
'''
request = self._get_request()
resp = request.post(self.ACCOUNT_VERIFY_URL, {
'email_address': email_address
})
return ('account' in resp)
# ---- SIGNATURE REQUEST METHODS -------------------
@api_resource(SignatureRequest)
def get_signature_request(self, signature_request_id, ux_version=None):
''' Get a signature request by its ID
Args:
signature_request_id (str): The id of the SignatureRequest to retrieve
ux_version (int): UX version, either 1 (default) or 2.
Returns:
A SignatureRequest object
'''
request = self._get_request()
parameters = None
if ux_version is not None:
parameters = {
'ux_version': ux_version
}
return request.get(self.SIGNATURE_REQUEST_INFO_URL + signature_request_id, parameters=parameters)
@api_resource_list(SignatureRequest)
def get_signature_request_list(self, page=1, ux_version=None):
''' Get a list of SignatureRequest that you can access
This includes SignatureRequests you have sent as well as received, but
not ones that you have been CCed on.
Args:
page (int, optional): Which page number of the SignatureRequest list to return. Defaults to 1.
ux_version (int): UX version, either 1 (default) or 2.
Returns:
A ResourceList object
'''
request = self._get_request()
parameters = {
"page": page
}
if ux_version is not None:
parameters['ux_version'] = ux_version
return request.get(self.SIGNATURE_REQUEST_LIST_URL, parameters=parameters)
def get_signature_request_file(self, signature_request_id, path_or_file=None, file_type=None, filename=None):
''' Download the PDF copy of the current documents
Args:
signature_request_id (str): Id of the signature request
path_or_file (str or file): A writable File-like object or a full path to save the PDF file to.
filename (str): [DEPRECATED] Filename to save the PDF file to. This should be a full path.
file_type (str): Type of file to return. Either "pdf" for a single merged document or "zip" for a collection of individual documents. Defaults to "pdf" if not specified.
Returns:
True if file is downloaded and successfully written, False otherwise.
'''
request = self._get_request()
url = self.SIGNATURE_REQUEST_DOWNLOAD_PDF_URL + signature_request_id
if file_type:
url += '?file_type=%s' % file_type
return request.get_file(url, path_or_file or filename)
def send_signature_request(self, test_mode=False, 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, ux_version=None):
''' Creates and sends a new SignatureRequest with the submitted documents
Creates and sends a new SignatureRequest with the submitted documents.
If form_fields_per_document is not specified, a signature page will be
affixed where all signers will be required to add their signature,
signifying their agreement to all contained documents.
Args:
test_mode (bool, optional): Whether this is a test, the signature request will not be legally binding if set to True. Defaults to False.
files (list of str): The uploaded file(s) to send for signature
file_urls (list of str): URLs of the file for HelloSign to download to send for signature. Use either `files` or `file_urls`
title (str, optional): The title you want to assign to the SignatureRequest
subject (str, optional): The subject in the email that will be sent to the signers
message (str, optional): The custom message in the email that will be sent to the signers
signing_redirect_url (str, optional): The URL you want the signer redirected to after they successfully sign.
signers (list of dict): A list of signers, which each has the following attributes:
name (str): The name of the signer
email_address (str): Email address of the signer
order (str, optional): The order the signer is required to sign in
pin (str, optional): The 4- to 12-character access code that will secure this signer's signature page
cc_email_addresses (list, optional): A list of email addresses that should be CC'd
form_fields_per_document (str): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
use_text_tags (bool, optional): Use text tags in the provided file(s) to create form fields
hide_text_tags (bool, optional): Hide text tag areas
metadata (dict, optional): Metadata to associate with the signature request
ux_version (int): UX version, either 1 (default) or 2.
Returns:
A SignatureRequest object
'''
self._check_required_fields({
"signers": signers
}, [{
"files": files,
"file_urls": file_urls
}]
)
params = {
'test_mode': self._boolean(test_mode),
'files': files,
'file_urls': file_urls,
'title': title,
'subject': subject,
'message': message,
'signing_redirect_url': signing_redirect_url,
'signers': signers,
'cc_email_addresses': cc_email_addresses,
'form_fields_per_document': form_fields_per_document,
'use_text_tags': self._boolean(use_text_tags),
'hide_text_tags': self._boolean(hide_text_tags),
'metadata': metadata
}
if ux_version is not None:
params['ux_version'] = ux_version
return self._send_signature_request(**params)
def send_signature_request_with_template(self, test_mode=False, template_id=None, template_ids=None, title=None, subject=None, message=None, signing_redirect_url=None, signers=None, ccs=None, custom_fields=None, metadata=None, ux_version=None):
''' Creates and sends a new SignatureRequest based off of a Template
Creates and sends a new SignatureRequest based off of the Template
specified with the template_id parameter.
Args:
test_mode (bool, optional): Whether this is a test, the signature request will not be legally binding if set to True. Defaults to False.
template_id (str): The id of the Template to use when creating the SignatureRequest. Mutually exclusive with template_ids.
template_ids (list): The ids of the Templates to use when creating the SignatureRequest. Mutually exclusive with template_id.
title (str, optional): The title you want to assign to the SignatureRequest
subject (str, optional): The subject in the email that will be sent to the signers
message (str, optional): The custom message in the email that will be sent to the signers
signing_redirect_url (str, optional): The URL you want the signer redirected to after they successfully sign.
signers (list of dict): A list of signers, which each has the following attributes:
role_name (str): Signer role
name (str): The name of the signer
email_address (str): Email address of the signer
pin (str, optional): The 4- to 12-character access code that will secure this signer's signature page
ccs (list of str, optional): The email address of the CC filling the role of RoleName. Required when a CC role exists for the Template. Each dict has the following attributes:
role_name (str): CC role name
email_address (str): CC email address
custom_fields (list of dict, optional): A list of custom fields. Required when a CustomField exists in the Template. An item of the list should look like this: `{'name: value'}`
metadata (dict, optional): Metadata to associate with the signature request
ux_version (int): UX version, either 1 (default) or 2.
Returns:
A SignatureRequest object
'''
self._check_required_fields({
"signers": signers
}, [{
"template_id": template_id,
"template_ids": template_ids
}]
)
params = {
'test_mode': self._boolean(test_mode),
'template_id': template_id,
'template_ids': template_ids,
'title': title,
'subject': subject,
'message': message,
'signing_redirect_url': signing_redirect_url,
'signers': signers,
'ccs': ccs,
'custom_fields': custom_fields,
'metadata': metadata
}
if ux_version is not None:
params['ux_version'] = ux_version
return self._send_signature_request_with_template(**params)
@api_resource(SignatureRequest)
def remind_signature_request(self, signature_request_id, email_address):
''' Sends an email to the signer reminding them to sign the signature request
Sends an email to the signer reminding them to sign the signature
request. You cannot send a reminder within 1 hours of the last reminder
that was sent. This includes manual AND automatic reminders.
Args:
signature_request_id (str): The id of the SignatureRequest to send a reminder for
email_address (str): The email address of the signer to send a reminder to
Returns:
A SignatureRequest object
'''
request = self._get_request()
return request.post(self.SIGNATURE_REQUEST_REMIND_URL + signature_request_id, data={
"email_address": email_address
})
def cancel_signature_request(self, signature_request_id):
''' Cancels a SignatureRequest
Cancels a SignatureRequest. After canceling, no one will be able to sign
or access the SignatureRequest or its documents. Only the requester can
cancel and only before everyone has signed.
Args:
signing_request_id (str): The id of the signature request to cancel
Returns:
None
'''
request = self._get_request()
request.post(url=self.SIGNATURE_REQUEST_CANCEL_URL + signature_request_id, get_json=False)
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, ux_version=None):
''' Creates and sends a new SignatureRequest with the submitted documents
Creates a new SignatureRequest with the submitted documents to be signed
in an embedded iFrame . If form_fields_per_document is not specified, a
signature page will be affixed where all signers will be required to add
their signature, signifying their agreement to all contained documents.
Note that embedded signature requests can only be signed in embedded
iFrames whereas normal signature requests can only be signed on
HelloSign.
Args:
test_mode (bool, optional): Whether this is a test, the signature request will not be legally binding if set to True. Defaults to False.
client_id (str): Client id of the app you're using to create this embedded signature request. Visit the embedded page to learn more about this parameter (https://www.hellosign.com/api/embeddedSigningWalkthrough)
files (list of str): The uploaded file(s) to send for signature
file_urls (list of str): URLs of the file for HelloSign to download to send for signature. Use either `files` or `file_urls`
title (str, optional): The title you want to assign to the SignatureRequest
subject (str, optional): The subject in the email that will be sent to the signers
message (str, optional): The custom message in the email that will be sent to the signers
signing_redirect_url (str, optional): The URL you want the signer redirected to after they successfully sign.
signers (list of dict): A list of signers, which each has the following attributes:
name (str): The name of the signer
email_address (str): Email address of the signer
order (str, optional): The order the signer is required to sign in
pin (str, optional): The 4- to 12-character access code that will secure this signer's signature page
cc_email_addresses (list, optional): A list of email addresses that should be CCed
form_fields_per_document (str): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
use_text_tags (bool, optional): Use text tags in the provided file(s) to create form fields
hide_text_tags (bool, optional): Hide text tag areas
metadata (dict, optional): Metadata to associate with the signature request
ux_version (int): UX version, either 1 (default) or 2.
Returns:
A SignatureRequest object
'''
self._check_required_fields({
"signers": signers,
"client_id": client_id
}, [{
"files": files,
"file_urls": file_urls
}]
)
params = {
'test_mode': self._boolean(test_mode),
'client_id': client_id,
'files': files,
'file_urls': file_urls,
'title': title,
'subject': subject,
'message': message,
'signing_redirect_url': signing_redirect_url,
'signers': signers,
'cc_email_addresses': cc_email_addresses,
'form_fields_per_document': form_fields_per_document,
'use_text_tags': self._boolean(use_text_tags),
'hide_text_tags': self._boolean(hide_text_tags),
'metadata': metadata
}
if ux_version is not None:
params['ux_version'] = ux_version
return self._send_signature_request(**params)
def send_signature_request_embedded_with_template(self, test_mode=False, client_id=None, template_id=None, template_ids=None, title=None, subject=None, message=None, signing_redirect_url=None, signers=None, ccs=None, custom_fields=None, metadata=None, ux_version=None):
''' Creates and sends a new SignatureRequest based off of a Template
Creates a new SignatureRequest based on the given Template to be
signed in an embedded iFrame. Note that embedded signature requests can
only be signed in embedded iFrames whereas normal signature requests can
only be signed on HelloSign.
Args:
test_mode (bool, optional): Whether this is a test, the signature request will not be legally binding if set to True. Defaults to False.
client_id (str): Client id of the app you're using to create this embedded signature request. Visit the embedded page to learn more about this parameter (https://www.hellosign.com/api/embeddedSigningWalkthrough)
template_id (str): The id of the Template to use when creating the SignatureRequest. Mutually exclusive with template_ids.
template_ids (list): The ids of the Templates to use when creating the SignatureRequest. Mutually exclusive with template_id.
title (str, optional): The title you want to assign to the SignatureRequest
subject (str, optional): The subject in the email that will be sent to the signers
message (str, optional): The custom message in the email that will be sent to the signers
signing_redirect_url (str, optional): The URL you want the signer redirected to after they successfully sign.
signers (list of dict): A list of signers, which each has the following attributes:
name (str): The name of the signer
email_address (str): Email address of the signer
pin (str, optional): The 4- to 12-character access code that will secure this signer's signature page
ccs (list of dict, optional): The email address of the CC filling the role of RoleName. Required when a CC role exists for the Template. Each dict has the following attributes:
role_name (str): CC role name
email_address (str): CC email address
custom_fields (list of dict, optional): A list of custom fields. Required when a CustomField exists in the Template. An item of the list should look like this: `{'name: value'}`
metadata (dict, optional): Metadata to associate with the signature request
ux_version (int): UX version, either 1 (default) or 2.
Returns:
A SignatureRequest object of the newly created Signature Request
'''
self._check_required_fields({
"signers": signers,
"client_id": client_id
}, [{
"template_id": template_id,
"template_ids": template_ids
}]
)
params = {
'test_mode': self._boolean(test_mode),
'client_id': client_id,
'template_id': template_id,
'template_ids': template_ids,
'title': title,
'subject': subject,
'message': message,
'signing_redirect_url': signing_redirect_url,
'signers': signers,
'ccs': ccs,
'custom_fields': custom_fields,
'metadata': metadata
}
if ux_version is not None:
params['ux_version'] = ux_version
return self._send_signature_request_with_template(**params)
# ---- REUSABLE FORM METHODS -----------------------
@api_resource(Template)
def get_template(self, template_id):
''' Gets a Template which includes a list of Accounts that can access it
Args:
template_id (str): The id of the template to retrieve
Returns:
A Template object
'''
request = self._get_request()
return request.get(self.TEMPLATE_GET_URL + template_id)
@api_resource_list(Template)
def get_template_list(self, page=1, page_size=None, account_id=None, query=None):
''' Lists your Templates
Args:
page (int, optional): Page number of the template List to return. Defaults to 1.
page_size (int, optional): Number of objects to be returned per page, must be between 1 and 100, default is 20.
account_id (str, optional): Which account to return Templates for. Must be a team member. Use "all" to indicate all team members. Defaults to your account.
query (str, optional): String that includes search terms and/or fields to be used to filter the Template objects.
Returns:
A ResourceList object
'''
request = self._get_request()
parameters = {
'page': page,
'page_size': page_size,
'account_id': account_id,
'query': query
}
return request.get(self.TEMPLATE_GET_LIST_URL, parameters=parameters)
# RECOMMEND: this api does not fail if the user has been added...
def add_user_to_template(self, template_id, account_id=None, email_address=None):
''' Gives the specified Account access to the specified Template
Args:
template_id (str): The id of the template to give the account access to
account_id (str): The id of the account to give access to the template. The account id prevails if both account_id and email_address are provided.
email_address (str): The email address of the account to give access to.
Returns:
A Template object
'''
return self._add_remove_user_template(self.TEMPLATE_ADD_USER_URL, template_id, account_id, email_address)
def remove_user_from_template(self, template_id, account_id=None, email_address=None):
''' Removes the specified Account's access to the specified Template
Args:
template_id (str): The id of the template to remove the account's access from.
account_id (str): The id of the account to remove access from the template. The account id prevails if both account_id and email_address are provided.
email_address (str): The email address of the account to remove access from.
Returns:
An Template object
'''
return self._add_remove_user_template(self.TEMPLATE_REMOVE_USER_URL, template_id, account_id, email_address)
def delete_template(self, template_id):
''' Deletes the specified template
Args:
template_id (str): The id of the template to delete
Returns:
A status code
'''
url = self.TEMPLATE_DELETE_URL
request = self._get_request()
response = request.post(url + template_id, get_json=False)
return response
# def get_template_files(self, template_id):
def get_template_files(self, template_id, filename):
''' Download a PDF copy of a template's original files
Args:
template_id (str): The id of the template to retrieve.
filename (str): Filename to save the PDF file to. This should be a full path.
Returns:
Returns a PDF file
'''
url = self.TEMPLATE_GET_FILES_URL + template_id
request = self._get_request()
return request.get_file(url, filename)
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, use_preexisting_fields=False):
''' Creates an embedded Template draft for further editing.
Args:
test_mode (bool, optional): Whether this is a test, the signature request created from this draft will not be legally binding if set to 1. Defaults to 0.
client_id (str): Client id of the app you're using to create this draft.
files (list of str): The file(s) to use for the template.
file_urls (list of str): URLs of the file for HelloSign to use for the template. Use either `files` or `file_urls`, but not both.
title (str, optional): The template title
subject (str, optional): The default template email subject
message (str, optional): The default template email message
signer_roles (list of dict): A list of signer roles, each of which has the following attributes:
name (str): The role name of the signer that will be displayed when the template is used to create a signature request.
order (str, optional): The order in which this signer role is required to sign.
cc_roles (list of str, optional): The CC roles that must be assigned when using the template to send a signature request
merge_fields (list of dict, optional): The merge fields that can be placed on the template's document(s) by the user claiming the template draft. Each must have the following two parameters:
name (str): The name of the merge field. Must be unique.
type (str): Can only be "text" or "checkbox".
use_preexisting_fields (bool): Whether to use preexisting PDF fields
Returns:
A Template object specifying the Id of the draft
'''
params = {
'test_mode': self._boolean(test_mode),
'client_id': client_id,
'files': files,
'file_urls': file_urls,
'title': title,
'subject': subject,
'message': message,
'signer_roles': signer_roles,
'cc_roles': cc_roles,
'merge_fields': merge_fields,
'use_preexisting_fields': use_preexisting_fields
}
return self._create_embedded_template_draft(**params)
# ---- TEAM METHODS --------------------------------
@api_resource(Team)
def get_team_info(self):
''' Gets your Team and a list of its members
Returns information about your team as well as a list of its members.
If you do not belong to a team, a 404 error with an error_name of
"not_found" will be returned.
Returns:
A Team object
'''
request = self._get_request()
return request.get(self.TEAM_INFO_URL)
@api_resource(Team)
def create_team(self, name):
''' Creates a new Team
Creates a new Team and makes you a member. You must not currently belong to a team to invoke.
Args:
name (str): The name of your team
Returns:
A Team object
'''
request = self._get_request()
return request.post(self.TEAM_CREATE_URL, {"name": name})
# RECOMMEND: The api event create a new team if you do not belong to any team
@api_resource(Team)
def update_team_name(self, name):
''' Updates a Team's name
Args:
name (str): The new name of your team
Returns:
A Team object
'''
request = self._get_request()
return request.post(self.TEAM_UPDATE_URL, {"name": name})
def destroy_team(self):
''' Delete your Team
Deletes your Team. Can only be invoked when you have a team with only one member left (yourself).
Returns:
None
'''
request = self._get_request()
request.post(url=self.TEAM_DESTROY_URL, get_json=False)
def add_team_member(self, account_id=None, email_address=None):
''' Add or invite a user to your Team
Args:
account_id (str): The id of the account of the user to invite to your team.
email_address (str): The email address of the account to invite to your team. The account id prevails if both account_id and email_address are provided.
Returns:
A Team object
'''
return self._add_remove_team_member(self.TEAM_ADD_MEMBER_URL, email_address, account_id)
# RECOMMEND: Does not fail if user has been removed
def remove_team_member(self, account_id=None, email_address=None):
''' Remove a user from your Team
Args:
account_id (str): The id of the account of the user to remove from your team.
email_address (str): The email address of the account to remove from your team. The account id prevails if both account_id and email_address are provided.
Returns:
A Team object
'''
return self._add_remove_team_member(self.TEAM_REMOVE_MEMBER_URL, email_address, account_id)
# ---- EMBEDDED METHODS ----------------------------
@api_resource(Embedded)
def get_embedded_object(self, signature_id):
''' Retrieves a embedded signing object
Retrieves an embedded object containing a signature url that can be opened in an iFrame.
Args:
signature_id (str): The id of the signature to get a signature url for
Returns:
An Embedded object
'''
request = self._get_request()
return request.get(self.EMBEDDED_OBJECT_GET_URL + signature_id)
@api_resource(Embedded)
def get_template_edit_url(self, template_id):
''' Retrieves a embedded template for editing
Retrieves an embedded object containing a template url that can be opened in an iFrame.
Args:
template_id (str): The id of the template to get a signature url for
Returns:
An Embedded object
'''
request = self._get_request()
return request.get(self.EMBEDDED_TEMPLATE_EDIT_URL + template_id)
# ---- UNCLAIMED DRAFT METHODS ---------------------
def create_unclaimed_draft(self, test_mode=False, files=None, file_urls=None, draft_type=None, subject=None, message=None, signers=None, cc_email_addresses=None, signing_redirect_url=None, form_fields_per_document=None, metadata=None, use_preexisting_fields=False):
''' 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
authenticated user to access the URL will claim the Draft and will be
shown either the "Sign and send" or the "Request signature" page with
the Draft loaded. Subsequent access to the claim URL will result in a
404. If the type is "send_document" then only the file parameter is
required. If the type is "request_signature", then the identities of the
signers and optionally the location of signing elements on the page are
also required.