Challenge Response in Webhook

Hey!

I’m trying to make a web hook to receive stripe events, however they want to do a challenge response before I can add the web hook URI. How would I return a json key provided in the POST body in the body of the response?

POST:
“body”: {
“type”: “url_verification”,
“token”: “Nc0V120SQ9fdeN8zF8MXBdSD”,
“challenge”: “1zp6ZmZ5eTOeJthMWRe9YTRl2EPMREvlv3OZrcjKwg8TVaTnNp7z”
}

They expect 1zp6ZmZ5eTOeJthMWRe9YTRl2EPMREvlv3OZrcjKwg8TVaTnNp7z back

Thanks!

Sorry for the late answer! It took me a while to come up with a way to do it currently without changing the code. It can be done with returning binary data.

Here a simple example workflow which receives the challenge via “GET” (to test easily) and the query parameter “challenge” returns it:

{
  "nodes": [
    {
      "parameters": {
        "path": "stripe",
        "responseMode": "lastNode",
        "responseData": "firstEntryBinary"
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].binary = {\n  data: {\n    data: new Buffer(items[0].json.query.challenge).toString('base64'),\n    mimeType: 'text/plain',\n  }\n}\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

So if test and you call the workflow like this:
http://localhost:5678/webhook-test/<WORKFLOW_ID>/webhook/stripe?challenge=test123

It should then return “test123” (without quotes)

Hey Jan, I wanted to thank you for writing that, definitely went above and beyond there.

I got it to work with Slack (I know I wrote stripe, mistyped there) by changing, it to post and then changing the javascript function “items[0].json.query.challenge” to “items[0].json.body.challenge”. After that they registered my callback URI perfectly.