How to test a webhook
It is recommended to test your
You can use your sandbox environment to create a webhook that will send events to an
Create a test endpoint
It is possible to create a very basic test
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)
- Ruby
- Python
- JavaScript
$ sudo apt-get install ruby-full
$ sudo apt-get install python3 python3-dev
$ sudo apt install nodejs
$ sudo npm install express
yum (CentOS, Fedora, ou RHEL)
- Ruby
- Python
- JavaScript
$ sudo yum install ruby
$ sudo yum install python3
$ curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
$ sudo yum install nodejs
Homebrew (macOS)
- Ruby
- Python
- JavaScript
$ brew install ruby
$ brew install python
$ brew install node
Then you have to install the necessary dependencies.
- Ruby
- Python
- JavaScript
$ gem install puma falcon webrick sinatra
$ pip install Flask
$ npm install express
Once the dependencies are installed, you can create the Ruby file that will be used to start a server.
- Ruby
- Python
- JavaScript
require 'sinatra'
require 'json'
post '/webhook' do
puts request.body.read
end
from flask import request, Flask
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def parse_request():
print(request.json)
return "Hello World!"
const express = require('express')
const app = express()
const port = 3000
app.use(express.json());
app.post('/webhook', (req, res) => {
console.log(req.body)
response.send(req.body);
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
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
/your-org/webhook
for example. Finally, the function will listen to the requests on this Start the test
- Ruby
- Python
- JavaScript
$ ruby file_name.rb
$ flask --app file_name run
$ node file_name.js
Create a test Webhook
To create a webhook you can send the following request to Cryptr services with your Sandbox
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
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 (
{
"__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