Webhooks

Webhooks contain "multi-part/form-data" content that includes both data and files.

All API documentation on webhooks can be found here: https://docs.documo.com/#create-webhook

Note: The server should respond with any 2** status so that we can then consider the webhook successful. If we receive any other status (i.e. 500 or 4**), the webhook will be rescheduled a total of seven times.

Webhook Retry Schedule

There will be seven attempts made prior to a failure. This schedule is as follows: 5s, 25s, 2m, 10m, 52m, 4h, 22h.
After that, you will receive an email notification with an error and webhook data. If the webhook has an attachment, it will not be included in the email.

Webhook Basic Auth

We recommended that your webhook URLs be protected using basic authentication. To use basic authentication, toggle use basic auth switcher in "Advanced Fax Routing" settings, seen here:

Note: The username and password will be converted to Base64 string and will be sent in an "authorization" header alongside each request. 

Webhook Receiving Example

Under node.js it is recommended to use "multer" package from npm. This will handle form data that we are sending and will convert it to a readable format.

See:
https://www.npmjs.com/package/multer

Example: 

const router = require('express').Router();
const multer = require('multer');
const httpAuth = require('http-auth');
const upload = multer({dest: 'uploads/'});

// Basic auth check
const auth = httpAuth.basic({}, (username, password, cb) => {
    // It is recommended to store username and password in environment variables
    cb(username === 'username' && password === 'password');
});

router.post('/webhook',
    upload.single('attachment'),
    auth.check(function (req, res) {

        // Webhook data
        console.log(JSON.parse(req.body.data));

        // Webhook attachment.
        console.log(req.file);

        res.sendStatus(200);
    }));

module.exports = router;
Did this answer your question?