title: How to configure eventNotification on DocuSign PowerForms/Templates
body: <h3>Question</h3>
  
  <p>I'd like for all the documents created by a single DocuSign Template/PowerForm to be configured with a webhook so that I don't need to <a href="https://docs.docusign.com/esign/guide/usage/status_and_events.html" rel="nofollow noreferrer">continuously poll every 15 minutes</a> to get completed documents. I've done a lot of reading, and want to know if this is even possible in the DocuSign API.</p>
  
  <h3>Background</h3>
  
  <p>I have a self-service waiver document: Users navigate to a URL, fill out their contact information (i.e. define a Recipient role), and expect that their completed waiver is recognized by a linked system.</p>
  
  <p>I have a <a href="https://www.docusign.com/developer-center/explore/features/templates" rel="nofollow noreferrer">DocuSign template</a> that is being used in a <a href="https://www.docusign.com/features-and-benefits/features/powerforms" rel="nofollow noreferrer">PowerForm</a>: Users navigate to the PowerForm's URL, and the PowerForm will let them create a new Envelope from the associated Template.</p>
  
  <p>I'd like for the documents created by this setup to automatically notify an HTTPS endpoint upon completion, via a standard <a href="https://www.docusign.com/developer-center/api-overview#webhooks" rel="nofollow noreferrer">webhook</a>.</p>
  
  <h3>Attempted solutions</h3>
  
  <p>The <a href="https://docs.docusign.com/esign/restapi/Envelopes/Envelopes/create/" rel="nofollow noreferrer"><code>Envelopes::create</code></a> method (<code>POST /v2/accounts/{accountId}/envelopes</code>) accepts an <code>eventNotification</code> parameter that can be used to configure webhooks. The <a href="https://www.docusign.com/developer-center/recipes/webhook-status" rel="nofollow noreferrer">webhook recipe</a> covers usage of this endpoint quite nicely. This would solve my problem, if I were creating every Envelope via an API request, but I like the ease of a copy-pastable URL that comes with a PowerForm.</p>
  
  <p>It's not documented, but it appears that <a href="https://docs.docusign.com/esign/restapi/Envelopes/Envelopes/update/" rel="nofollow noreferrer"><code>Envelopes::update</code></a> (<code>PUT /v2/accounts/{accountId}/envelopes/{envelopeId}</code>) may support configuring notifications on an already-created envelope. I could repeatedly <a href="https://docs.docusign.com/esign/restapi/Envelopes/Envelopes/listStatus/" rel="nofollow noreferrer">query the most current envelopes</a> for my template, update the notifications on in-progress envelopes and process the completed ones, but that's no better than polling.</p>
  
  <p>I browsed the <a href="https://docs.docusign.com/esign/restapi/" rel="nofollow noreferrer">REST API</a>, specifically the <a href="https://docs.docusign.com/esign/restapi/Templates/" rel="nofollow noreferrer">Templates</a> and <a href="https://docs.docusign.com/esign/restapi/PowerForms/" rel="nofollow noreferrer">PowerForms</a> categories, but I don't see any obvious way to configure either resource to set <code>eventNotification</code> on created envelopes.</p>
  
  <p>Here's a quick code dump of some of the API exploration I've done:</p>
  
  <pre><code>#!/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 = (
      "&lt;DocuSignCredentials&gt;"
      "&lt;Username&gt;" + username + "&lt;/Username&gt;"
      "&lt;Password&gt;" + password + "&lt;/Password&gt;"
      "&lt;IntegratorKey&gt;" + integrator_key + "&lt;/IntegratorKey&gt;"
      "&lt;/DocuSignCredentials&gt;"
  )
  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})
  </code></pre>
  
  <h3>Constraints</h3>
  
  <p>My account is not configured to have <a href="https://www.docusign.com/developer-center/api-overview#docusign-connect" rel="nofollow noreferrer">DocuSign Connect</a>, which would allow me to notify the HTTPS endpoint <em>every</em> time a document in my account is completed. I'm on a shared account (with other irrelevant Envelopes/Templates being used), so this is not an ideal solution anyway.</p>