Blog
Home/

Common API Tasks🐈: Add a Connect Webhook to your Envelopes

Author Inbar Gazit
Inbar GazitSr. Manager, Developer Content
Summary3 min read

Learn how to add a Connect webhook to your envelopes using the eSignature REST API with useful code examples

    • What is Docusign Connect?
    • Two ways to set up Docusign Connect
    • Code please!
    • Additional resources

    Table of contents

    en-US

    Greetings, everyone! If you are reading this and wondering, what are "common API asks," I encourage you to take a look at the first two posts in the series. In the first post, I showed you how to set a custom email message for your envelope recipients, and in the second, I explained how to get the tab information from your envelopes. In this third post in the series I’m going to show you how to set a custom webhook using Docusign's webhook technology, Docusign Connect.

    What is Docusign Connect?

    As developers, you write integrations that typically make API requests to Docusign and either retrieve information or tell Docusign to perform a certain action. In this model, your code initiates the call and Docusign responds to your request upon receiving it: this method is called polling. There’s another model where Docusign initiates a request to your app to indicate some event occured in the system. In that model, the developer sets up a dedicated URL that Docusign calls into when objects were updated in the system: this method is called a webhook. For example, Docusign Connect will let you know when there has been a change of status for an envelope in your account.

    Two ways to set up Docusign Connect

    Docusign Connect can be set in two different ways. Both ways require developers to make Docusign eSignature API calls (there's no way to do that from the web tool). The first way is to set a global Docusign Connect webhook for the account. That means a Docusign account user with administrative privileges can create a Connect Configuration. The Connect Configuration would apply for all users and envelopes in the account. This blog post is focused on the second approach, which allows a developer to request that a specific envelope be set to call the specified webhook using Docusign Connect. The envelope must be created via the Docusign eSignature API and the call, as I’m going to show you here, would include the information needed to register Docusign Connect for this envelope. This approach has the advantage of being flexible, since you don’t have to process events for all the envelopes in the account. It also skirts the maximum number of Connect Configurations, which is limited to 100.

    Code please!

    Happy to oblige. For the snippets below, I assume you have other parts of the code that add recipients and documents to the envelope. Here is how to add a custom Docusign Connect webhook notification for your envelope in our six SDK languages:

    C#

    EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
    var eventNotification = new EventNotification();
    // Set up the endpoint URL to call (it must be using HTTPS and at least TLS1.1 or higher)
    eventNotification.Url = "https:\\myapp.somedomain.com";
    // Docusign will retry on failure if this is set
    eventNotification.RequireAcknowledgment = "true";
    // This would send the documents together with the event to the endpoint
    eventNotification.IncludeDocuments = "true";
    // Allows you to see this in the Docusign Admin Connect logs section
    eventNotification.LoggingEnabled = "true";
    var envelopeEvents = new List<envelopeevent>();
    // In this case we only add a single envelope event, when the envelope is completed. You can also add events for recipients
    envelopeEvents.Add(new EnvelopeEvent { EnvelopeEventStatusCode = "completed", IncludeDocuments = "true" });        
    eventNotification.EnvelopeEvents = envelopeEvents;
    envelopeDefinition.EventNotification = eventNotification;</envelopeevent>
    

    Java

    EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
    EventNotification eventNotification = new EventNotification();
    // Set up the endpoint URL to call (it must be using HTTPS and at least TLS1.1 or higher)
    eventNotification.setUrl("https:\\myapp.somedomain.com");
    // Docusign will retry on failure if this is set
    eventNotification.setRequireAcknowledgment("true");
    // This would send the documents together with the event to the endpoint
    eventNotification.setIncludeDocuments("true");
    // Allows you to see this in the Docusign Admin Connect logs section
    eventNotification.setLoggingEnabled("true");
    java.util.List<envelopeevent> envelopeEvents = new java.util.arrayList<envelopeevent>();
    // In this case we only add a single envelope event, when the envelope is completed. You can also add events for recipients
    EnvelopeEvent envelopeEvent = new EnvelopeEvent();
    envelopeEvent.setEnvelopeEventStatusCode("completed"); 
    envelopeEvent.setIncludeDocuments("true");
    envelopeEvents.add(envelopeEvent);   
    eventNotification.setEnvelopeEvents(envelopeEvents);
    envelopeDefinition.setEventNotification(eventNotification);</envelopeevent></envelopeevent>
    

    Node.js

    let envelopeDefinition = new docusign.EnvelopeDefinition();
    let eventNotification = new docusign.EventNotification();
    // Set up the endpoint URL to call (it must be using HTTPS and at least TLS1.1 or higher)
    eventNotification.url = 'https:\\myapp.somedomain.com';
    // Docusign will retry on failure if this is set
    eventNotification.requireAcknowledgment = 'true';
    // This would send the documents together with the event to the endpoint
    eventNotification.includeDocuments = 'true';
    // Allow you to see this in the Docusign Admin Connect logs section
    eventNotification.loggingEnabled = 'true';
    let envelopeEvents = [];
    // In this case we only add a single envelope event, when the envelope is completed. You can also add events for recipients
    let envelopeEvent = new docusign.EnvelopeEvent();
    envelopeEvent.envelopeEventStatusCode = 'completed'; 
    envelopeEvent.includeDocuments = 'true';
    envelopeEvents.push(envelopeEvent);   
    eventNotification.envelopeEvents = envelopeEvents;
    envelopeDefinition.eventNotification = eventNotification;
    

    PHP

    $envelopeDefinition = new \Docusign\eSign\Model\EnvelopeDefinition();
    $eventNotification = new \Docusign\eSign\Model\EventNotification();
    # Set up the endpoint URL to call (it must be using HTTPS and at least TLS1.1 or higher)
    $eventNotification->setUrl('https:\\myapp.somedomain.com');
    # Docusign will retry on failure if this is set
    $eventNotification->setRequireAcknowledgment('true');
    # This would send the documents together with the event to the endpoint
    $eventNotification->setIncludeDocuments('true');
    # Allows you to see this in the Docusign Admin Connect logs section
    $eventNotification->setLoggingEnabled('true');
    $envelopeEvents = [];
    # In this case we only add a single envelope event, when the envelope is completed. You can also add events for recipients
    $envelopeEvent = new \Docusign\eSign\Model\EnvelopeEvent();
    $envelopeEvent->setEnvelopeEventStatusCode('completed'), 
    $envelopeEvent->setIncludeDocuments('true');
    array_push($envelopeEvents, $envelopeEvent);   
    $eventNotification->setEnvelopeEvents($envelopeEvents);
    $envelopeDefinition->setEventNotification($eventNotification);
    
    
    
    

    Python

    envelope_definition = EnvelopeDefinition()
    event_notification = EventNotification()
    # Set up the endpoint URL to call (it must be using HTTPS and at least TLS1.1 or higher)
    event_notification.url = 'https:\\myapp.somedomain.com'
    # Docusign will retry on failure if this is set
    event_notification.require_acknowledgment = 'true'
    # This would send the documents together with the event to the endpoint
    event_notification.include_documents = 'true'
    # Allows you to see this in the Docusign Admin Connect logs section
    event_notification.logging_enabled = 'true'
    envelope_events = []
    # In this case we only add a single envelope event, when the envelope is completed. You can also add events for recipients
    envelope_event = EnvelopeEvent()
    envelope_event.envelope_event_status_code = 'completed' 
    envelope_event.include_documents = 'true'
    envelope_events.append(envelope_event)   
    event_notification.envelope_events = envelope_events
    envelope_definition.event_notification = event_notification
    

    Ruby

    envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
    event_notification = EventNotification.new
    # Set up the endpoint URL to call (it must be using HTTPS and at least TLS1.1 or higher)
    event_notification.url = 'https:\\myapp.somedomain.com'
    # Docusign will retry on failure if this is set
    event_notification.require_acknowledgment = 'true'
    # This would send the documents together with the event to the endpoint
    event_notification.include_documents = 'true'
    # Allows you to see this in the Docusign Admin Connect logs section
    event_notification.logging_enabled = 'true'
    envelope_events = []
    # In this case we only add a single envelope event, when the envelope is completed. You can also add events for recipients
    envelope_event = DocuSign_eSign::EnvelopeEvent.new
    envelope_event.envelope_event_status_code = 'completed' 
    envelope_event.include_documents = 'true'
    envelope_events.push(envelope_event)   
    event_notification.envelope_events = envelope_events
    envelope_definition.event_notification = event_notification
    

    So there you have it. Now you know how to add your custom Docusign Connect webhook for the envelopes you create in your app. If you have any questions on this or any other Docusign API related topic, feel free to email me. Look forward to my next blog post in the series next month!

    Additional resources

    Author Inbar Gazit
    Inbar GazitSr. Manager, Developer Content

    Inbar Gazit has been with Docusign since 2013 in various engineering roles. Since 2019 he has focused on developer content. Inbar works on code examples including the launchers, available on GitHub in eight languages, and helps build sample apps showcasing the various Docusign APIs. He is also active on StackOverflow, answering your questions. Inbar can be reached at inbar.gazit@docusign.com.

    More posts from this author

    Related posts

    • Common API Tasks🐈: List all your Maestro workflows using the Maestro API
      Common API Tasks

      Common API Tasks🐈: List all your Maestro workflows using the Maestro API

      Author Inbar Gazit
      Inbar Gazit
    • Common API Tasks🐈: Find a web form by name

      Common API Tasks🐈: Find a web form by name

      Author Inbar Gazit
      Inbar Gazit
    Common API Tasks🐈: Find a web form by name

    Common API Tasks🐈: Find a web form by name

    Author Inbar Gazit
    Inbar Gazit

    Discover what's new with Docusign IAM or start with eSignature for free

    Explore Docusign IAMTry eSignature for Free
    Person smiling while presenting