Hello, greetings of the day. I'm working with an ...
# help
s
Hello, greetings of the day. I'm working with an XML body for an API request, and I need to extract an attribute to send via a webhook. I've successfully extracted the attribute and included it in the API response. However, when I try to use it in the webhook's serveEventListeners, I encounter an error:
attribute="[ERROR: null is not valid XML]"
. Could anyone advise me on how to resolve this? @Lee Turner, any guidance you could provide would be much appreciated!
below is exactly what i've used
Copy code
XML Request:
<ns2:ReqPay xmlns:ns2="<http://npci.org/upi/schema/>">
    <Head ver="2.0" ts="2021-01-17T11:18:11+05:30" orgId="929390493" msgId="randomMsgId"/>
    <Payer addr="shikhar@gios" name="Bobi Jacob" seqNum="1" type="PERSON" code="0000">
    </Payer>
</ns2:ReqPay>

Admin Mapping:
{
    "request": {
        "method": "POST",
        "urlPattern": "/testing",
        "headers": {
            "Content-Type": {
                "equalTo": "application/xml"
            }
        }
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/xml"
        },
        "transformers": [
            "response-template"
        ],
        "body": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:Ack xmlns:ns2=\"<http://npci.org/upi/schema/>\" api=\"npciApi\" reqMsgId=\"{{randomValue length=32 type='ALPHANUMERIC'}}\" addr=\"{{xPath request.body '/ReqPay/Payer/@addr'}}\" ts=\"{{now format='yyyy-MM-dd\\'T\\'HH:mm:ssXXX'}}\"/>"
    },
    "serveEventListeners": [
        {
            "name": "webhook",
            "parameters": {
                "method": "POST",
                "url": "<https://nnccdd.requestcatcher.com/testing0100>",
                "headers": {
                    "Content-Type": "application/xml"
                },
                "delay": {
                    "type": "fixed",
                    "milliseconds": 800
                },
                "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ns2:RespPay xmlns:ns2=\"<http://npci.org/upi/schema/>\" xmlns:ns3=\"<http://npci.org/cm/schema/>\">\n\t<Head msgId=\"xxx\" orgId=\"NPCI\" ts=\"{{now format='yyyy-MM-dd\\'T\\'HH:mm:ssXXX'}}\" ver=\"2.0\"/>\n\t<Ref addr=\"{{xPath request.body '/ReqPay/Payer/@addr'}}\" />\n\t</Resp>\n</ns2:RespPay>"
            }
        }
    ]
}

API Response i got:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Ack xmlns:ns2="<http://npci.org/upi/schema/>" api="npciApi" reqMsgId="e4gqglqg1xadizkpnvkr3ls1j5666pjk" addr="arunl@gip1" ts="2024-05-28T05:39:52Z"/>

Webhook response i got:
<?xml version="1.0" encoding="UTF-8"?>
<ns2:RespPay xmlns:ns2="<http://npci.org/upi/schema/>" xmlns:ns3="<http://npci.org/cm/schema/>">
    <Head msgId="xxx" orgId="NPCI" ts="2024-05-28T05:39:52Z" ver="2.0"/>
    <Ref addr="[ERROR: null is not valid XML]" />
    </Resp>
</ns2:RespPay>
r
Hi, the issue here may be that you need to use
originalRequest
rather than
request
when referring to the initial request in the webhook response template.
👍 1
👏 1
s
@Rafe Arnold Thank you soo much this worked. Can you please point me to documentation for this or example which have explained this concept? Thank you @Lee Turner
l
s
Thankyou @Lee Turner for the doc reference.
👍 1