Send new orders to another system
Use a hook to post every new order to the endpoint of another application.
On this page
This recipe sends each new order to another application, for example an accounting system, as soon as it is saved.
1. Prepare the endpoint
The other system needs an address that accepts a POST request with JSON, for example https://erp.example.com/api/orders/. It receives the format described in Hook and action data.
A minimal receiver in Node.js that logs the order:
const http = require('http');
http.createServer(function(req, res) {
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', function() {
const hook = JSON.parse(body);
console.log('New order', hook.data.name, 'for', hook.data.x02);
res.end('OK');
});
}).listen(9000);2. Set the hook
- Open the settings of the Orders table.
- In the Hooks tab, enter the address in Create.
- Click SUBMIT.
3. Try it
Create an order. The other system receives the order with its number, customer, amount and status, and the name of the user who created it.
To also send changes, enter the same address in Update. The receiver can tell new orders from changes by dtupdated, which is empty for a new record.