Your First Result Webhook
In this tutorial we will learn how to get result of the task to our server.
This tutorial we will use webhook.site for mocking our server. This site gives you a webhook URL, and you can receive POST request to this URL.
0. Before we start
Navigate to webhook.site and create a new webhook. It will generate a new webhook URL for you.
Your POST URL will be shown as following:
https://webhook.site/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
Copy this URL, we will use it in the next step.
Do not close this webhook site until the end of this tutorial.
1. Create a Task with Webhook
Previous step we learn how to create a task. Now we will learn how to create a task with webhook. It is quite simple, you just need to provide notification_settings
in the request.
This is the code to create a task with web hook. Added parameters are highlighted.
import requests
api_key = "YOUR_API_KEY"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
}
queue_name = "my_first_queue"
url = "http://api.qrambo.io/queues/{queue_name}/tasks"
response = requests.post(url, json={
"input_data": {
# You can add any data in here if you want
hello: "world"
},
"notification_settings": {
"strategy": "UNION",
"endpoint": "https://webhook.site/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"headers": {
"YourCustomHeader": "YourCustomValue"
},
"events_to_notify": [
"TASK_FINISHED" # There are other events you can use, please refer to the documentation for more information.
]
}
}, headers=headers)
print(response.json()) # if it returns success == true, it is ok
Navigate the dashboard and check the task has been created.
In this tutorial we used Task Notification feature, but you can use Queue notification, and it is much more flexable. Please refer to the documentation for more information.
2. Finalize the Task in Dashboard with random JSON
Click self assign and add some random json like this:
{
"my_result": "hello back!"
}
This self assign is a feature for development only. For this tutorial, we are using it just for testing the webhook, so we need to finalize the task.
In next step, we will implement basic HTML interface to review the task.
3. Check WebHook site Get the Result
Navigate to the webhook site, you will see the request has been received.
4. Next Step
OK, now we know how to create a task and get the result from the webhook.
In the next step, we will implement basic HTML interface to review the task.