Open mrbraca15 opened 7 years ago
You can't do this:
webHooks.trigger(shortName, payloadData, additionalData);
The third parameter is reserved for the headers
.
If you wanna pass more data, just add it as an additional property of your payloadData
object.
Example:
webHooks.trigger(shortName, {myData: 'hello', moreData: 'even more data'});
emitter.on('*.success', (shortname, statusCode, body)=> {
var myData = body.myData
var moreData = body.moreData
// ...
});
hello thanks for the answer but in the body parameter i received the request response of the url configured in the shorname.
Ok, I was supposing that the web-server "mirrors" your body request. You can't manipulate the server's response. It's not either a good practice.
webHooks.trigger(shortName, {myData: 'hello', moreData: 'even more data'});
emitter.on('*.success', (shortname, statusCode, body)=> {
var myData = body.myData
var moreData = body.moreData
// ...
});
did the above but the body contains the response body, any help to track what have been sent from my side as in the request body,
thank you
this how i am triggering the webhook :
// dispatch the webhook :
await webHooks.trigger('OrderCreated', {data: data}, {Authorization: Authorization});
and here is the function I am using to log all the webhooks dispatched :
emitter.on('*.failure', async function (shortname, statusCode, body) {
let TIMESTAMP = new Date().toLocaleString("en-US", {timeZone: "Asia/Riyadh"});
let DATE = new Date().toLocaleDateString("en-US", {timeZone: "Asia/Riyadh"}).replace("/","-").replace("/","-").substring(0,9);
console.log(colors.error('ERROR on trigger webhook ' + shortname + ' with status code', statusCode, 'and body', body , 'At : ',TIMESTAMP))
let obj = {
shortname,
statusCode,
TIMESTAMP,
body,
}
// console.log({obj})
await (async () => {
let event = []
event.push({} = obj)
const csv = new ObjectsToCsv(event);
// Save to file:
await csv.toDisk(`./logs/FAILED-WEBHOOKS-${DATE}-${shortname}.csv`, { append: true });
// Return the CSV file as string:
// console.log(await csv.toString());
})();
})
anyway to track the body of the request I am dispatching, the data object, thanks again
it's up to your app logic to keep track of what you're dispatching.
hello i need to send a additional data on trigger event for use it after on succes event, for example:
thanks