coinbase-commerce-node icon indicating copy to clipboard operation
coinbase-commerce-node copied to clipboard

Error occured Invalid payload provided. No JSON object could be decoded

Open ccurves opened this issue 3 years ago • 3 comments

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);
  }
);

Screenshot (348)

Screenshot (347)

ccurves avatar Jun 14 '21 15:06 ccurves

I have the same issue, and i don't know where is the error

jachicas avatar Jun 14 '21 23:06 jachicas

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.

abubakarnasiru273 avatar Sep 04 '21 22:09 abubakarnasiru273

I have same issue, I did this

//server file
//app.use(bodyParser.json())

app.use(bodyParser.json({
        verify: (req, res, buf) => {
          req.rawBody = buf
        }
    }))

Solution

shahzadthathal avatar Apr 10 '22 11:04 shahzadthathal