docusign-esign-php-client
docusign-esign-php-client copied to clipboard
EventNotification - Webhook - JSON
Hello,
I'm using EventNotification class to define my webhook. I can see you can choose between XML/JSON when I use the website to create the hook :
But I can't find a way to ask for JSON when creating the hook programmatically like :
$eventNotification = new EventNotification();
$eventNotification->setUrl('https://webhook.site/123456');
// How to ask for JSON ?
Is this possible? Thanks for you help!
You can change the format from XML to JSON by adding eventData to your eventNotification object
The event data should contain the following information:
"eventData":{
"version": "restv2.1",
"format": "json",
"includeData": ["tabs","payment_tabs","custom_fields","powerform","recipients","folders","extensions","attachments","Documents"]
},
You can change "includeData" to contain only the information you want included in your notification
This is the class you should be using for this: https://github.com/docusign/docusign-php-client/blob/82fddd73429e0b86ea82f503c7831d8541f049a5/src/Model/ConnectEventData.php
For anyone else battling this I finally worked it out but I thought that Edwin's comment could have been more helpful. This is how I ended up getting it to behave in the way I wanted.
I don't know if everything here is required but now it's working I'm not messing with it!
private function createEventNotification()
{
$eventData = new \DocuSign\eSign\Model\ConnectEventData();
$eventData->setVersion('restv2.1');
$eventData->setFormat('json');
$eventData->setIncludeData(['custom_fields', 'tabs', 'recipients', 'powerform_data' ]);
$eventNotification = new \DocuSign\eSign\Model\EventNotification([
'url' => env('DS_WEBHOOK_URL'),
'event_data' => $eventData,
'delivery_mode' => 'SIM',
'logging_enabled' => 'true',
'include_documents' => 'false',
'use_soap_interface' => 'false',
'envelope_events' => [
new \DocuSign\eSign\Model\EnvelopeEvent([
'envelope_event_status_code' => 'completed'
])
]
]);
return $eventNotification;
}