WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.35k stars 197 forks source link

Use mocked response data in Webhook body data #1081

Closed rmeshksar closed 3 months ago

rmeshksar commented 3 months ago

Hi, Imagine a mocked API returns response from this template:

{
   "id": "{{Random Type='Guid'}}",
   "name":  "John"
}

This mock API triggers a Webhook call with some delays.

Is it possible in the body data of the WebhookRequest, use the value of id of the response of the original call?

StefH commented 3 months ago

I think you can use:

request.bodyAsJson.id

See https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating#the-request-model

rmeshksar commented 3 months ago

Would that be request of the original call or response from the original call? I am looking to use the response form the original call.

rmeshksar commented 3 months ago

This worked for me: {{JsonPath.SelectToken response.bodydata.bodyAsString 'Id'}}