Skip to main content

How to test a webhook

Learn how to test your webhooks to improve their processing performance before they go into production.

It is recommended to test your

The fallback content to display on prerendering
and your webhooks before going live for an optimal experience.

You can use your sandbox environment to create a webhook that will send events to an

The fallback content to display on prerendering
that you have created locally. This way you can ensure good communication between the two entities.

Create a test endpoint

It is possible to create a very basic test

The fallback content to display on prerendering
to listen to events. For this we will use Sinatra, Flask or ExpressJS which are Ruby, Python & NodeJS libraries.

The first thing to do is to install Ruby, Python or NodeJS on your machine. For a complete installation tutorial, you can consult:


apt (Debian or Ubuntu)

$ sudo apt-get install ruby-full

yum (CentOS, Fedora, ou RHEL)

$ sudo yum install ruby

Homebrew (macOS)

$ brew install ruby

Then you have to install the necessary dependencies.

$ gem install puma falcon webrick sinatra

Once the dependencies are installed, you can create the Ruby file that will be used to start a server.

webhook-server.rb

require 'sinatra'
require 'json'

post '/webhook' do
puts request.body.read
end


Save it in .rb, .py or .js format depending on the language you use. This very short code will make it possible to run a server in an extremely simple way. First you have to import the necessary dependencies then define which method to listen to. In our case, these are HTTP POST requests. In the examples above, the /webhook

The fallback content to display on prerendering
was used but you can choose whichever one you want. It could also be /your-org/webhook for example. Finally, the function will listen to the requests on this
The fallback content to display on prerendering
and simply display in the terminal the body of the requests received. In this way, we will be able to ensure the correct reception and the correct format of the requests.

Start the test

The fallback content to display on prerendering
using the command:

$ ruby file_name.rb

Create a test Webhook

To create a webhook you can send the following request to Cryptr services with your Sandbox

The fallback content to display on prerendering
. To learn more about how to create a webhook, see the How to define the events to listen to guide.

cURL
curl -X POST '${cryptr_service_url}/api/v2/webhooks' \
-d 'name=webhook-name' \
-d 'target_url=https://your_target_url.fr' \ #Replace 4567 with 3000 for Python and JavaScript
-d 'event_codes[]=all'

Trigger an event

To

The fallback content to display on prerendering
an event corresponding to the webhook above, you can use our test endpoint. For this you can use the following query:

cURL
curl -X POST '${cryptr_service_url}/api/v2/webhook-events/trigger-test' \
-d 'event_code=dir_sync.user.provision.success'

Once this query is executed you should receive a result similar to this on your target URL (

The fallback content to display on prerendering
):

Example of received event
{
"__domain__": "3-belges",
"__environment__": "sandbox",
"__type__": "Event",
"code": "dir_sync.updated_user",
"data": {
"__type__": "DirectorySyncEvent",
"change": "update",
"directory_sync_id": "2cbd4ad8-1f3c-4ea0-84b6-691d4d469e57",
"provider": "okta",
"resource": {
"changes": {
"new_values": {
"address": {
"country": "FR",
"formatted": "12 rue des freres lumières\n68200 Mulhouse, France",
"locality": "Mulhouse",
"postal_code": "68200",
"region": "Alsace",
"street_address": "12 rue des freres lumières"
},
"phone_numbers": [
{
"default": false,
"phone_country_code": 33,
"phone_national_number": "345676543",
"primary": true,
"type": "work",
"value": "+33345676543"
},
{
"default": false,
"phone_country_code": 33,
"phone_national_number": "687435543",
"primary": true,
"type": "mbile",
"value": "+33687435543"
}
],
"profile": {
"family_name": "O'neil",
"given_name": "April",
"preferred_username": "April O'neil",
},
"updated_at": "2023-06-06T08:49:33"
},
"previous_values": {
"address": {
"country": null,
"formatted": "12 rue des freres lumières\nMulhouse",
"locality": "Mulhouse",
"postal_code": null,
"region": null,
"street_address": "12 rue des freres lumières"
},
"phone_numbers": [],
"profile": {
"family_name": null,
"given_name": "Aprils",
"preferred_username": "O'neil",
},
"updated_at": "2023-06-06T08:06:21"
}
},
"id": "b4702922-5868-4db8-bcd9-87ab40af50ed",
"type": "User"
}
},
"errors": null,
"params": {
"addresses": [
{
"country": "FR",
"locality": "Mulhouse",
"postalCode": "68200",
"region": "Alsace",
"streetAddress": "12 rue des freres lumières"
}
],
"phoneNumbers": [
{
"primary": true,
"type": "work",
"value": "+33345676543"
},
{
"primary": true,
"type": "mbile",
"value": "+33687435543"
}
],
"name": {
"familyName": "O'neil",
"givenName": "April"
},
"displayName": "April O'neil",
},
"issued_at": "2023-06-06T08:49:33.075265Z",
"webhook_id": "webhook_2QauvX3scYnpadurUTdjrd59QrE"
}

If so, the webhooks and your

The fallback content to display on prerendering
is working properly.