Wiremock webhook and response won't return same random value

22 views Asked by At

I am using wiremock-standalone-3.4.2, trying to emulate a 3rd party that upon a request from me responds with a certain field with UUID value X and sends the same value X to a webhook. The value X needs to change from request to request so it needs to be randomized. I can't seem to find a way to have the emulator return in the response the same random value it send to the webhook. Any ideas?

Tried using {{randomValue type='UUID'}} in both places but this expectedly resulted in 2 different random values. -

{
  "priority": 1,
  "request": {
    "method": "POST",
    "urlPath": "/v1/businesses"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "id": "{{randomValue type='UUID'}}"
}},
"serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "http://some-url/",
        "headers": {
          "Content-Type": "application/json",
        },
        "body": "{\"id\": \"{{randomValue type='UUID'}}\"}"}}]}
1

There are 1 answers

0
Lee On

Currently there is no way to do this natively WireMock. We do have a proposal to implement this exact thing but at the moment it hasn't been addressed. I think there are a number of ways to achieve this at the moment:

  1. Pass the UUID into the request (as a header for example) and then this would be available in the response and the webhook
  2. Use the WireMock State Extension to add the generated UUID to shared state and then this would be available in the response and the webhook