Hi, We are trying to make a callback request using...
# help
m
Hi, We are trying to make a callback request using webhooks after a success mocked api call. But it is not making callback api call. Adding the mappings for the same -
Copy code
{
    "request": {
      "method": "POST",
      "url": "/transfer"
    },
    "response": {
      "status": 200,
      "jsonBody": {
        "message": "transfer succeded!"
      },
      "headers": {
        "Content-Type": "application/json"
      }
    },
    "serveEventListeners": [
        {
            "name": "webhook",
            "parameters": {
                "method": "POST",
                "url": ""<https://my-target-host/callback>"",
                "headers": {
                    "Content-Type": "application/json",
                    "Accept": "application/json",
                    "Authorization": "Bearer {AUTH_TOKEN}"
                },
                "body": {"oldState":{},"newState":{}}
            }
        }
    ]
  }
Are we missing something here 🤔 , Can you please help us with this? Note - value for AUTH_TOKEN is hardcoded for now. cc: @kaushik dey
l
Hi, what version of WireMock are you using?
k
version 3.5.3
🆙 1
l
Your json mapping mostly works but there are a few issues with what you posted. The
url
value in the callback section has too many quotes around it and the
body
element in the callback section is not the same as the
jsonBody
element in the response section. The value of the
body
element needs to be a string. This works fine for me:
Copy code
{
  "request": {
    "method": "POST",
    "url": "/transfer"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "message": "transfer succeded!"
    },
    "headers": {
      "Content-Type": "application/json"
    }
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<https://my-target-host/callback>",
        "headers": {
          "Content-Type": "application/json",
          "Accept": "application/json",
          "Authorization": "Bearer {AUTH_TOKEN}"
        },
        "body": "{\"oldState\": {}, \"newState\": {}}"
      }
    }
  ]
}
👀 1
m
Hi @Lee Turner, Thank you for the suggestion. It seems like callback endpoint is still not getting hit after applying the suggestions. Also we are unable to debug this issue. Do you know if there is any way to get the sense of actual issues/errors with the callback request 🤔
l
I setup a test here - https://webhook.site It was hit fine in my test so not sure what it would be in yours. Possibly something to do with the auth if your endpoint requires authorisation ?
m
Yeah, It requires authorisation and I provided a hardcoded bearer token for now.
l
Do you have any logs you can look at for the url you are trying to hit with the callback? Is there anything in the wiremock logs that tells you what response the calllback got?
In my logs there was -
2024-04-29 13:38:36.164 Webhook POST request to <https://webhook.site/xxxxxxxxxx> returned status 200
m
Is there anything in the wiremock logs that tells you what response the callback got?
Right now we are using wiremock docker image for the same, so I am not really sure if we can put any extra logs over there 🤔
In my logs there was -
2024-04-29 13:38:36.164 Webhook POST request to <https://webhook.site/xxxxxxxxxx> returned status 200
We also didn't see any issue with the mock api call (
/transfer
)
k
Yes we are also trying similar approach, checking in the logs if our endpoint got called to verify but we don't see any logs
m
> Do you have any logs you can look at for the url you are trying to hit with the callback? Yeah we do have logs in our application but seems like callback itself is not passing the authentication or some other issue for the callback url and we are not getting any logs
l
Right now we are using wiremock docker image for the same, so I am not really sure if we can put any extra logs over there
Wiremock will log the status of the callback already. You might have to set the
verbose
flag to true which you can do in the docker image. Not sure what else to suggest.
👀 1
m
That helps 🎉, At least we can debug the issues. Will let you know if we need any further information.
l
Awesome, great news
🎉 1