https://linen.dev logo
#help
Title
# help
a

Alx Dark

12/01/2023, 3:01 PM
Hello everyone. When I match a variable in a request, can I refer to that variable in a webhook response? All the examples use originalRequest in the webhook template. Here's an example, where I'd like to capture part of the path as the variable "tn" and then refer to it in the JSON I send via the webhook extension...but that doesn't work:
Copy code
{
  "mappings": [
    {
      "request": {
        "method": "DELETE",
        "urlPathTemplate": "/path/{tn}",
        "pathParameters": {
          "tn": {
            "matches": "[0-9]+"
          }
        }
      },
      "serveEventListeners": [
        {
          "name": "webhook",
          "parameters": {
            "method": "POST",
            "url": "/webhook/path",
            "headers": {
              "Content-Type": "application/json"
            },
            "body": "{\"tn\":\"{{tn}}\",\"timestamp\":\"{{now}}\"}}"
          }
        }
      ]
    }
  ]
}
If the request is the only variable passed into the webhook templating system, then I guess I'm hoping there's something like
originalRequest.parameters
that I can refer to in order to get at that variable. (btw I'm aware that I can get at a path element via
originalRequest.path.[#]
but I that's somewhat fragile and hard for others to follow.) Thanks in advance for any help on this!
t

Tom

12/01/2023, 4:20 PM
You can only get this via
<http://originalRequest.path.tn|originalRequest.path.tn>
but I’m not sure why you’d consider this any more fragile than if it was under a
parameters
object instead?
a

Alx Dark

12/01/2023, 4:36 PM
I wasn't aware you could access it under originalRequest.path — that's actually perfect for what I was looking for and answers my question — thank you!
I didn't know these variables were added back to the
path
object...that makes perfect sense though.
t

Tom

12/01/2023, 4:43 PM
It should work - I’ll admit I’ve not tried this!
a

Alx Dark

12/01/2023, 7:01 PM
Sadly, it doesn't seem to work.
t

Tom

12/06/2023, 8:53 PM
You’re right, seems we’re not passing the relevant context into that template model at the moment. Enhancement issue here: https://github.com/wiremock/wiremock/issues/2523
8 Views