503 Error When Testing With Webhooks

Hello, my previous post was automatically hidden because the system thought it was spam.

Here is the original link that explains it all: https://developer.squareup.com/forums/t/503-error-when-using-webhook-api/8053

If you can help me, that would be great. Thank you!

Are you using one of our examples for verifying the webhook? A 503 would be coming from your server which means that Square didn’t get the 2xx response within 10 seconds. Is a 503 also returned with test webhooks? :slightly_smiling_face:

Hi Bryan,

Thank you for the reply.

I am using the example from the documentation, but had to adapt it because I am using Express.

Here is my code:

exports.square_account_created = async (req, res, next) => {
  // The URL where event notifications are sent.
  const NOTIFICATION_URL = 'https://ajd249rdaproject.website:3000/auth/square_account_created';
  // The signature key defined for the subscription.
  const SIGNATURE_KEY = '************';
  // isFromSquare generates a signature from the url and body and compares it to the Square signature header.
  function isFromSquare(signature, body) {
    const hmac = crypto.createHmac('sha256', SIGNATURE_KEY);
    hmac.update(NOTIFICATION_URL + body);
    const hash = hmac.digest('base64');
    return hash === signature;
  }

  try {
    const signature = req.headers['x-square-hmacsha256-signature'];
    if (isFromSquare(signature, req.body)) {
      res.sendStatus(200);
      console.info("Request body: " + req.body);
    } else {
      res.sendStatus(403);
    }
    res.end()
  } catch (error) {
    if (!err.statusCode) {
      err.statusCode = 500;
    }
    next(err);
  }
}

Note that I did put the correct signature key from my webhook subscription. I tested it using Postman and it works when sending a POST request to the notification URL. However, when I try it with the ‘send test event’ I get a 503 error.

When I go to the site URL I’m getting a not found. Is the URL valid? :slightly_smiling_face:

Yes the URL is valid. The: {“error”:{“message”:“SOMETHING WRONG WRONG 404 - Not found.”}}
you see is just something I put there for default if you are trying to make a request that I did not set up. Entering the URL in the browser is making a GET request that I did not set anything for so it defaults to my generic response of 404 not found text. If you make a POST request to that URL though something different will happen. It would run the function I posted previously.

I just wanted to say that I solved it. It ended up being that I did not bundle my ca-bundle.crt and certificate.crt files for my SSL to verify it. I noticed that this was an issue in Postman because it said that it had trouble verifying it so figured maybe it’s an SSL issue.

Low and behold, I got the Postman issue to go away by verifying it properly and then webhooks worked!

Great! Glad to hear you figured it out. :slightly_smiling_face: