How to read splunk webhook payload from post request? - webhooks

I am trying to get the JSON payload from post request using Splunk webhook as an alert action. My webhook url is http://hostname/api/splunk_alert
My nodejs server listening post request
app.post('/api/splunk_alert', function(request, response){
console.log(request.body); // your JSON
response.send(request.body); // echo the result back
});
Can someone please let me know if I am in right direction?
Thanks

Yep, its looking OK so far. Do you need /api/ to your input express path?
app.post('/api/splunk_alert', function(request, response){
console.log(request.body); // your JSON
response.send(request.body); // echo the result back
});
Refer to https://docs.splunk.com/Documentation/Splunk/7.3.1/Alert/Webhooks for details of the contents of the web-hook.

Related

Where would I find the payload with a Wix webhook?

I have a couple Wix webhooks pointed to a couple routes on my server. The webhook is in fact hitting my routes, but I'm not seeing the payload anywhere. The documentation says it's in the form of a JWT sent in the body of the request. The body is empty though. Am I missing something?
Here is my route receiving the request:
router.post("/app-installed", (req, res) => {
console.log("req.body: ", req.body);
console.log("headers", req.headers);
res.sendStatus(200);
});

Access URL query Params in an Express POST route

I have a NodeJS/Express application.
From an url endpoint titled: localhost:3000/form?someProp=someValue&somethingElse=someOtherValue
This page submits a form to another Express endpoint.
I submit to an Express POST endpoint. I know in a GET endpoint I could access the query params via req.query, but I cannot seem to do that in a POST request.
Is there a way to access the query params from the request in a POST route?
(other than splicing the header.referrer... which I may just have to do)
Here are some code snippets:
If I submit to the first route it works, if I submit to the second... it does not.
router.get('/test',
(req, res) => {
console.log(req.query); // {someProp: someValue, somethingElse: someOtherValue }
}
);
router.post('/test2',
(req, res) => {
console.log(req.query); // returns {}
}
);
So I tried to send a simple request to test it and got everything working without doing anything special (The only thing extra I have is that I'm using body-parser middleware from npm):
app.use(bodyParser.json({limit: '50mb'}));
Then I tried this simple route and got the result query params as you can see in the picture attached.
http://localhost:8080/test?test=1&what=2
Any chance you're sending the other form request from the client in a different way? try looking at the network in chrome and see if you sending what you expecting. Obviously, there is something missing here as it worked for me without doing anything special.

How to get req.body from Facebook's data deletion URL call?

I've implemented the "sign in with Facebook" authorization method for my Express.js Node app. Since the app is hosted in the EU, Facebook requires it to have a data deletion request callback URL.
I've created an endpoint for the data deletion request, but whenever I make Facebook call that endpoint both req.body and req.query are empty - if I've understood correctly the body should contain a signed_request that could be used to e.g. verify the caller.
My CORS settings should be fine and I've tested my endpoint by calling it from Postman. The endpoint is able to receive a POST request with a JSON body without any problem.
So, what am I doing wrong - why does it seem like Facebook is calling my endpoint with a POST request that has an empty body?
My endpoint:
import express from 'express'; // 4.17.1
const router = express.Router();
router.post('/fb_data_deletion', (req, res, next) => {
console.log(req.body); // {}
console.log(req.query); // {}
if (!req.body || !req.body.signed_request) {
console.log('Bad request'); // Ends up here whenever Facebook calls this route
return req.sendStatus(400);
}
// verify request, delete user's data + other code here
});
Turns out Facebook isn't sending a POST request that uses Content-Type application/json but application/x-www-form-urlencoded.
To get the body of Facebook's POST request I had to add the following line to my app.js where the Node server is being set up:
app.use(express.urlencoded());

Nodejs doesnt receive jsondata

My Node.js server is not able to send the data it receives back to the browser. It is able to send self-made data like this
app.post('/login', (req,res) =>{
console.log(req.body);
res.setHeader('Content-Type', 'application/json');
res.json({test: "test info",test2: "still testing"});//works
//res.json(req.body);//does not work
})
In the fetch POST request, I have set the header 'Content-Type': 'application/json'.
In the firefox debugger, I can see that the information is sent via POST.
I have tried stuff like
res.json(req.body);
res.json(req.body.pass);
res.json({pass:+req.body.pass});//response in browser -> {"pass":null}
res.json("{pass:"+req.body.pass+"}");//response in browser -> "{pass:undefined}"
Could someone tell me why the Node.js server doesn't receive the JSON data?
Have you installed the body-parser
? Otherwise express wont convert the body of the POST request to a JSON object that you can access with req.body.pass

How can I respond to incoming Twilio calls and SMS messages using node.js?

In my application I'm using the twilio node.js module to receive an sms, send an sms, receive a call and make an outgoing call. I figured out how to send an sms and make a call. But I don't know how to respond to incoming calls and SMS messages. How can I use node to respond to these?
When Twilio receives a call to your phone number, it will send an HTTP request to a URL you configure in the admin console:
What Twilio expects in return from this HTTP request is a set of XML instructions called TwiML that will tell Twilio what to do in response to the call. For example, let's say that you wanted to respond to a phone call by saying "thank you" and then playing a music file. If you wanted to do this in node, you might consider using this node library and the express framework to send a TwiML response:
var twilio = require('twilio'),
express = require('express');
// Create express app with middleware to parse POST body
var app = express();
app.use(express.urlencoded());
// Create a route to respond to a call
app.post('/respondToVoiceCall', function(req, res) {
//Validate that this request really came from Twilio...
if (twilio.validateExpressRequest(req, 'YOUR_AUTH_TOKEN')) {
var twiml = new twilio.TwimlResponse();
twiml.say('Hi! Thanks for checking out my app!')
.play('http://myserver.com/mysong.mp3');
res.type('text/xml');
res.send(twiml.toString());
}
else {
res.send('you are not twilio. Buzz off.');
}
});
app.listen(process.env.PORT || 3000);
Good luck - hope this is what you were looking for.

Resources