Guest User

Untitled

a guest
Jan 27th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import requests
  3.  
  4.  
  5. username = 'user@example.com'
  6. password = 'some-sensitive-password'
  7. integrator_key = 'abcdef01-2345-6789-0abcdef0123456789'
  8.  
  9.  
  10. # Authenticate to the DocuSign API, get the base URL for subsequent requests
  11. authenticate_str = (
  12. "<DocuSignCredentials>"
  13. "<Username>" + username + "</Username>"
  14. "<Password>" + password + "</Password>"
  15. "<IntegratorKey>" + integrator_key + "</IntegratorKey>"
  16. "</DocuSignCredentials>"
  17. )
  18. headers = {'X-DocuSign-Authentication': authenticate_str,
  19. 'Accept': 'application/json'}
  20. api_base = 'https://demo.docusign.net/restapi/v2/'
  21. resp = requests.get(api_base + 'login_information', headers=headers)
  22. base_url = resp.json()['loginAccounts'][0]['baseUrl']
  23.  
  24. # Identify all templates in my account
  25. resp = requests.get(base_url + '/templates', headers=headers)
  26. all_templates = resp.json()['envelopeTemplates']
  27.  
  28. # (Find my template, explore ways I could modify it with PUT, etc.)
  29. template_id = find_desired_template(all_templates)
  30. resp = requests.get(base_url + '/templates/{}'.format(template_id), headers=headers)
  31.  
  32. # Find just status changed envelopes from some recent date/datetime
  33. resp = requests.get(base_url + '/envelopes',
  34. params={'from_date': '2018-01-26'}, headers=headers)
  35.  
  36. # Configure just a single envelope to have push notifications
  37. envelope_id = resp.json()['envelopes'][0]['envelopeId']
  38.  
  39. # Configure this _one_ envelope to notify us when completed.
  40. # WARNING: This isn't repeatable: The next auto-created envelope won't work
  41. event_notification = {
  42. "url": "https://my-own-api.example.com/some/endpoint",
  43. "loggingEnabled": "true",
  44. "requireAcknowledgment": "true",
  45. "useSoapInterface": "false",
  46. "includeCertificateWithSoap": "false",
  47. "signMessageWithX509Cert": "false",
  48. "includeDocuments": "true",
  49. "includeEnvelopeVoidReason": "true",
  50. "includeTimeZone": "true",
  51. "includeSenderAccountAsCustomField": "true",
  52. "includeDocumentFields": "true",
  53. "includeCertificateOfCompletion": "true",
  54.  
  55. # Only notify on completion
  56. "envelopeEvents": [
  57. {"envelopeEventStatusCode": "completed"}
  58. ],
  59. "recipientEvents": [
  60. {"recipientEventStatusCode": "Completed"},
  61. ],
  62. }
  63.  
  64. requests.put(base_url + '/envelopes/{}'.format(envelope_id),
  65. headers=headers,
  66. json={'eventNotification': event_notification})
Add Comment
Please, Sign In to add comment