Skip to main content

Connect a webhook

If you want to send parsed data directly to your server in real-time, you can use the Webhooks feature. A webhook is a POST endpoint on your server that receives data from DocumentPro.

You can create a webhook and set your webhook endpoint in the webhook section under the settings page.

Webhook settings

Webhook payload#

The webhook payload will contain an event, timestamp and data field. Here is an example.

{    "event": "file_request_status_change",    "timestamp": "2023-07-30T19:05:29.565249",    "data: {      "request_id": "your-request-id",      "request_status": "completed",      "response_body": {          "file_name": "your-file-name",          "file_presigned_url": "temporary-url-to-your-file",          "user_error_msg": null,          "template_id": "your-template-id",          "template_type": "receipt",          "template_title": "Receipt",          "num_pages": 2,          "result_json_data": {}      },      "created_at": "2023-07-30T19:05:10.696893",      "updated_at": "2023-07-30T19:05:29.565249"    }}

The request_status fields can be one of completed, failed, exception, pending or processing.

When the request_status is completed, the result_json_data field will contain the parsed data.

Example webhook implementations#

Flask (Python)#

from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])def webhook():    # Verify if request is json    if request.is_json:        data = request.get_json()                action = data.get('event')        request_status = data.get('data', {}).get('request_status')                print(f'Received action: {action}')        print(f'Received request_status: {request_status}')
        # You can process the data here as needed
        return jsonify({'message': 'Received'}), 200    else:        return jsonify({'error': 'Expected application/json data'}), 400
if __name__ == '__main__':    app.run(host='0.0.0.0', port=5000)

Express (Node.js)#

const express = require('express');const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.post('/webhook', (req, res) => {    const data = req.body;        const action = data.event;    const requestStatus = data.data?.request_status;
    console.log(`Received action: ${action}`);    console.log(`Received request_status: ${requestStatus}`);
    // Process the data as needed
    res.json({message: 'Received'});});
app.listen(5000, () => {    console.log('Server is running on port 5000');});