Generate UUID and use in both response and webhook

1,076 views
Skip to first unread message

Cristi Stefan

unread,
Nov 8, 2021, 10:20:52 AM11/8/21
to wiremock-user
Hello,

I am trying to work out how I can do the following - stub a POST which will return an UUID and then perform a webhook with the same UUID as generated in the response. Is this possible ?

Something like this:
{
"request": {
"urlPath": "/applicants",
"method": "POST"
},
"response": {
"status": 200,
"jsonBody": {
"id": "{{randomValue type='UUID'}} --- THIS IS WHERE ID IS GENERATED
}
},
"postServeActions": [
{
"name": "webhook",
"parameters": {
"method": "POST",
"url": "http://6576-34-242-39-217.ngrok.io/{{ID}}", --- HERE I WANT TO USE SAME ID
"delay": {
"type": "fixed",
"milliseconds": 3000
},
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"payload": {
"id": "{{ID}}",--- HERE I WANT TO USE SAME ID
}
}
}
}
]
}.


Is this supported ?

Thanks :) 

Pete

unread,
Nov 9, 2021, 6:04:03 PM11/9/21
to wiremock-user
To assign the randomValue as a variable you'd use syntax like this
  {{#assign 'ID'}}{{randomValue type='UUID'}}{{/assign}}
but unfortunately that variable's scope appears to be limited to the object where it's declared - so a variable assigned in response is empty in postServeActions.

However, if you had the ability in your test to generate and send the value in an HTTP header, called uuid say, then you can retrieve that from both response and postServeActions, as {{request.headers.uuid}} and {{originalRequest.headers.uuid}} respectively
Reply all
Reply to author
Forward
0 new messages