coinbase-commerce-node
coinbase-commerce-node copied to clipboard
Error occured Invalid payload provided. No JSON object could be decoded
I having been battling this error for weeks now, read hundreds of resources that has just proven futtile and contacted coinbase support without getting any response from them. When I try testing the webhook from the coinbase Api I get this error "Remote server at 07b0a16c5735.ngrok.io returned an HTTP 400" and in my console I get "Error occured Invalid payload provided. No JSON object could be decoded"
I have attached screenshots of the errors I am encountering and this my code for the endpoint;
app.post(
"/endpoint", (request, response) => {
var event;
console.log(request.headers);
try {
event = Webhook.verifyEventBody(
request.rawBody,
request.headers["x-cc-webhook-signature"],
webhookSecret
);
} catch (error) {
console.log("Error occured", error.message);
return response.status(400).send("Webhook Error:" + error.message);
}
console.log("Success", event.id);
console.log(request.rawBody);
response.status(200).send("Signed Webhook Received: " + event.id);
}
);
I have the same issue, and i don't know where is the error
Hello, I was able to fix the issue by first debugging on request.rawbody, I noticed it is undefined, so I move the rawbody function to where I am starting my function then set app.use directly to it and I received a success message.
If you are receiving that error probably it is from your rawbody not defined.
I have same issue, I did this
//server file
//app.use(bodyParser.json())
app.use(bodyParser.json({
verify: (req, res, buf) => {
req.rawBody = buf
}
}))