Hello, everyone! I have a question regarding call...
# help
b
Hello, everyone! I have a question regarding callback templating. I'll divide it in 3 steps 1. Our service A sends a request with
Content-Type: application/x-www-form-urlencoded
. In request service A sends a certain param (I'll come back to it later on) 2. Stub is supposed to respond with a json, which contains
operationId
(generated UUID). 3. Lastly, our stub should also send a callback, which should be
application/x-www-form-urlencoded
and contain two specific params. A param from initial request (from step 1) and the same
operationId
from response (from step 2) I tried to write a mapping for this task, but callback just doesn't work I'll attach json mapping in thread
Copy code
{
  "uuid": "236238ca-df12-41d6-8d88-882606e889ae",
  "name": "POST /api/merchantapi/paymentOrderCardId.do",
  "request": {
    "url": "/api/merchantapi/paymentOrderCardId.do",
    "method": "POST"
  },
  "response": {
    "status": 200,
    "jsonBody": {
      "errorCode": 0,
      "errorMessage": "",
      "info": "test",
      "operationId": "{{randomValue type='UUID'}}",
      "redirect": "test"
    },
    "headers": {
      "Content-Type": "application/json",
      "Connection": "close"
    }
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<http://i.deleted.the.host.for.privacy.sake/api/v1/redbox/callback>",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        "body": "currency=860&error_code=0&is_3ds=false&operation_status=success&operation_type=deposit&amount=15000000&order_number=2ad86d13-6e6b-4ced-853d-6553f8127f80&order_id={{formData request.body 'form' urlDecode=true}}{{form.orderId}}&merchant_order_params=%7B%22account_to_card%22%3Anull%2C%22recurrent%22%3Anull%2C%22split_p2p%22%3Afalse%2C%22debit_only_p2p%22%3Afalse%2C%22bdp%22%3Anull%2C%22case%22%3Anull%2C%22phoneNumber%22%3Anull%2C%22epos_cash_advance%22%3Afalse%2C%22cpg%22%3Anull%2C%22ali_params%22%3Anull%2C%22ali%22%3Anull%2C%22p2p%22%3A%7B%22flow_type%22%3A%22p2p_debit%22%2C%22sender_name%22%3A%22UNKNOWN%22%2C%22sender_address%22%3A%22UNKNOWN%2C%20UNKNOWN%22%2C%22sender_city%22%3A%22UNKNOWN%22%2C%22sender_country_code%22%3A%22RUS%22%2C%22sender_postal_code%22%3A%22UNKNOWN%22%2C%22sender_account%22%3Anull%2C%22receiver_account%22%3Anull%2C%22receiver_name%22%3Anull%2C%22transfer_id%22%3Anull%2C%22rates%22%3A%5B%5D%7D%2C%22installment%22%3Anull%2C%22uzum%22%3Anull%2C%22avia%22%3Anull%7D&terminal_id=136&operation_id=8a2c2ae0-8049-496e-af9e-b790ccb34c4e&blank_amount=15000000&action_code=500&attributes=%5B%5D&fee_amount=50000&blank_amount=15000000"
      }
    }
  ]
}
t
Did the webhook not even fire?
b
it didn't
Guess I used the formData incorrectly in the webhook body
Copy code
order_id={{formData request.body 'form' urlDecode=true}}{{form.orderId}}
this part
t
If you’re on the latest version of WireMock any errors in generating the webhook call will be attached to the request log. So if you visit /__admin/requests and find the relevant request there should be a sub-event saying what happened to the webhook.
b
I'll check it shortly
I checked and it turns out there is an NPE exception while executing a webhook. Not sure what's the reason by the stacktrace Does webhook functionality support templating and retrieving data from requests?
l
Can you post the stacktrace?
Just one thing, in your webhook body, to reference the
request
you need to use
originalRequest
rather than
request
- https://wiremock.org/docs/webhooks-and-callbacks/#using-data-from-the-original-request
Might be worth updating that first and then trying again
b
Here's the stacktrace
@Lee Turner thank you! I'll check it out
Is there a way to retrieve information from x-www-form-urlencoded request?
t
I’m pretty certain the issue will have been due to using
request
which is null in a webhook context
b
Hi, guys once again I still have one question Does wiremock support retrieving data from
x-www-form-urlencoded
Content-Type in request and using it in response?