Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import requests
- username = 'user@example.com'
- password = 'some-sensitive-password'
- integrator_key = 'abcdef01-2345-6789-0abcdef0123456789'
- # Authenticate to the DocuSign API, get the base URL for subsequent requests
- authenticate_str = (
- "<DocuSignCredentials>"
- "<Username>" + username + "</Username>"
- "<Password>" + password + "</Password>"
- "<IntegratorKey>" + integrator_key + "</IntegratorKey>"
- "</DocuSignCredentials>"
- )
- headers = {'X-DocuSign-Authentication': authenticate_str,
- 'Accept': 'application/json'}
- api_base = 'https://demo.docusign.net/restapi/v2/'
- resp = requests.get(api_base + 'login_information', headers=headers)
- base_url = resp.json()['loginAccounts'][0]['baseUrl']
- # Identify all templates in my account
- resp = requests.get(base_url + '/templates', headers=headers)
- all_templates = resp.json()['envelopeTemplates']
- # (Find my template, explore ways I could modify it with PUT, etc.)
- template_id = find_desired_template(all_templates)
- resp = requests.get(base_url + '/templates/{}'.format(template_id), headers=headers)
- # Find just status changed envelopes from some recent date/datetime
- resp = requests.get(base_url + '/envelopes',
- params={'from_date': '2018-01-26'}, headers=headers)
- # Configure just a single envelope to have push notifications
- envelope_id = resp.json()['envelopes'][0]['envelopeId']
- # Configure this _one_ envelope to notify us when completed.
- # WARNING: This isn't repeatable: The next auto-created envelope won't work
- event_notification = {
- "url": "https://my-own-api.example.com/some/endpoint",
- "loggingEnabled": "true",
- "requireAcknowledgment": "true",
- "useSoapInterface": "false",
- "includeCertificateWithSoap": "false",
- "signMessageWithX509Cert": "false",
- "includeDocuments": "true",
- "includeEnvelopeVoidReason": "true",
- "includeTimeZone": "true",
- "includeSenderAccountAsCustomField": "true",
- "includeDocumentFields": "true",
- "includeCertificateOfCompletion": "true",
- # Only notify on completion
- "envelopeEvents": [
- {"envelopeEventStatusCode": "completed"}
- ],
- "recipientEvents": [
- {"recipientEventStatusCode": "Completed"},
- ],
- }
- requests.put(base_url + '/envelopes/{}'.format(envelope_id),
- headers=headers,
- json={'eventNotification': event_notification})
Add Comment
Please, Sign In to add comment