https://linen.dev logo
#general
Title
# general
t

TommyTran2023

01/19/2024, 8:51 AM
Hi everyone, I need to mock a webhook which using data from response body. how can I do that, here is my JSON { "request": { "method": "POST", "urlPath": "/transform" }, "response": { "status": 200, "body": "{\"message\": \"success\", \"transactionId\": \"{{randomValue length=10 type='ALPHANUMERIC'}}\"}", "headers": { "Content-Type": "application/json" } }, "serveEventListeners": [ { "name": "webhook", "parameters": { "method": "POST", "url": "https://webhook.site/9c32fadb-b542-4edf-a530-85a012064566", "headers": { "Content-Type": "application/json" }, "body": "{\"systemId\": \"{{jsonPath response.body '$.transactionId'}}\"}" } } ] }
l

Lee Turner

01/19/2024, 9:57 AM
Hi, i don't think the response is available in the templating system for webhooks. From looking at the documentation it seems you can only use the original request in the templating of the webhook payload:
Copy code
{
  "request": {
    "method": "POST",
    "urlPath": "/webhooks"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "message": "success",
      "transactionId": "{{jsonPath request.body '$.id'}}"
    },
    "headers": {
      "Content-Type": "application/json"
    },
    "transformers": [
      "response-template"
    ]
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<http://host.docker.internal:7070/callback-logger/api/callback>",
        "headers": {
          "Content-Type": "application/json"
        },
        "body": "{\"systemId\": \"{{jsonPath originalRequest.body '$.id'}}\"}"
      }
    }
  ]
}
t

TommyTran2023

01/19/2024, 10:06 AM
yeah, for example, scenario is, create a product -> response contain id -> i need to get the id from the response to call get details. Do you have idea how to achieve that?
l

Lee Turner

01/19/2024, 10:16 AM
I can't think of a way to get access to the same value in the response and the webhooks payload at the moment other than sending the id as a header in the request for your test. That way the value will be available in the response and webhook
We do have an issue raised about this so it is on the radar - https://github.com/wiremock/wiremock/issues/2359
6 Views