Search code examples
jsonpine-scriptwebhooks

Empty body on alert trading view webhook


I'm currently testing some indicator/strategy and would like to automate things. I configure somes webhook with alerts with JSON formated strings like :

alert("{'heyyy':'oohhhh!'}", freq = alert.freq_all)  

but when the alert is triggered, webhook sended and i reveive the call on my server (node.js), the body is empty : {}

i setup the alert on "every alert() call"

i also try with alertcondition but the result is the same : empty body.

Thanks


Solution

  • I figure how to do that, there were a few issues

    1 - We must use simple quote as wrapper and double quotes for properties in stringify JSON

    str = "{'hey':'oh!'}" // bad
    str = '{"hey":"oh:"}' // good
    

    2 - server side (node JS) my body parser is now setup to receive plan text too

     app.use(bodyParser.text({ type: "*/*" }));
    

    Note, if your JSON string is setup with the wrong quotes , the JSON.parse() won't work