hi guyss want to ask question related to `response...
# help
g
hi guyss want to ask question related to
response
that generated by wiremock can i access the
response
json key? this is the
response json
that i stored in
__files
folder
Copy code
{
    "data": {
        "query_id": {{jsonPath request.body '$.user_id'}}{{randomValue length=10 type='NUMERIC'}}
    },
    "message": "",
    "status": "OK"
}
i want the
query_id
used in the callback can i store that
query_id
into a variable? and how to achieve that?
l
The easiest way to do this at the moment is with the state extension - https://github.com/wiremock/wiremock-state-extension
g
wow thats cool, thankyouu Lee
have a good day
will try on it
👍 1
hellooo @Lee Turner i have recordState like this
Copy code
{
  "name": "recordState",
  "parameters": {
    "context": "{{jsonPath response.body '$.data.query_id'}}",
    "state": {
      "queryId": "{{jsonPath response.body '$.data.query_id'}}"
    }
  }
}
but how to retrieve it? i tried like this in my callback
Copy code
{
                    "name": "webhook",
                    "parameters": {
                        "method": "POST",
                        "url": "<https://test.requestcatcher.com/callback/eagle>",
                        "headers": {
                            "Content-Type": "application/json"
                        },
                        "body": "{\"status_id\":\"{{#if (jsonPath response.body \'$.data.query_id\')}}{{state context=(jsonPath response.body \'$.data.query_id\') property=\'queryId\'}}{{else}}defaultValue{{/if}}\"}"
                        
                    }
                }
but it always return the
defaultValue
am i missed something? thankyouu
i updated the webhook using this
Copy code
{
  "name": "webhook",
  "parameters": {
    "method": "POST",
    "url": "<https://dadit.requestcatcher.com/callback/eagle>",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "\"status_id\":{{state context=\"jsonPath response.body '$.data.query_id'\" property='queryId'}}"
  }
}
and the log is like this
Copy code
mockingbird  | Response:
mockingbird  | HTTP/1.1 200
mockingbird  | Content-Type: [application/json]
mockingbird  | Matched-Stub-Id: [90811e28-e7dd-4da3-ae80-671024f6b8ed]
mockingbird  | 
mockingbird  | 2024-05-16 09:34:47.200 Context '17157633961669999': created
mockingbird  | 2024-05-16 09:34:47.201 Context '17157633961669999': property 'queryId' updated
mockingbird  | 2024-05-16 09:34:47.203 Context 'jsonPath response.body '$.data.query_id'': property 'queryId' not found, using `null`
mockingbird  | 2024-05-16 09:34:48.249 Webhook POST request to <https://test.requestcatcher.com/callback/eagle> returned status 200
mockingbird  | 
mockingbird  | request caught
but the
queryId
still empty
done case closed~ found the solution 🙇
🙌 1
l
Excellent, could you post the solution here for others to find?
g
so the
context
shouldnt be so complicated, just make a simpler one
Copy code
"serveEventListeners": [
                {
                    "name": "recordState",
                    "parameters": {
                        "context": "queryId",
                        "state": {
                            "queryId": "{{jsonPath response.body '$.data.query_id'}}"
                        }
                    }
                },
                {
                    "name": "webhook",
                    "parameters": {
                        "method": "POST",
                        "url": "<https://test.requestcatcher.com/callback/eagle>",
                        "headers": {
                            "Content-Type": "application/json"
                        },
                        "body": "\"status_id\":{{state context='queryId' property='queryId'}}"
                    }
                }
            ]
i think the
readme.md
of that repo should be simplify for the
context
itself hahahaha so not make anyone confuse for how to use it~ at least the documentation can be related on each section
l
Awesome, nice work on getting that sorted. Thanks for posting the solution
🙌 1