I try to create a mock webhook request, which will be triggered when request /transform is call
in webhook request body will get the id from response body id. How can I achieve that?
{
"request": {
"method": "POST",
"urlPath": "/transform"
},
"response": {
"status": 200,
"body": "{\"message\": \"success\", \"id\": \"{{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": "{\"id\": \"{{jsonPath response.body '$.id'}}\"}"
}
}
]
}
I'd try with body-transformer, but still not able to get the id value from response
"transformers":[
"body-transformer"
]
This conversation was had on the Wiremock community slack here - https://wiremock-community.slack.com/archives/C03NAEH5LVA/p1705654286090779
The answers are replicated here for completeness:
The response object is not 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:
Request body:
At the moment the only way to simulate what you are looking for is to send in the value as a value in the request body (as above) or as a request header in your test. That way the value will be available in the response and webhook.
This isn't ideal and we do have an issue raised to address this - https://github.com/wiremock/wiremock/issues/2359