on ‎2020 Apr 29 4:37 PM
Hi,
I'm trying to extract some variables from a SOAP XML based payload sent into my API proxy. From examples I've found it apparently should be possible by constructing the XPath as follows to match my payload:
/soapenv:Envelope/soapenv:Body/rrq:Comp/Comp/SystemName/text()
The API Proxy is setup as a SOAP pass-through, so I'm trying to use the extracted variables to assert some business logic. However, the variable never gets assigned value :0/
If it is possible to extract variables from a SOAP payload, could someone share an example of the policy and payload?
Thanks!
Request clarification before answering.
Hey Logan,
yes, you can extract variables from an XML payload.
I am not very deep into the technical details of API Management, but this is how it works for me (using the online SAP Gateway Demo System).
The payload that comes back for the resource "/ProductSet('HT-1060')" of the ES5 system is as follows:
<?xml version="1.0" encoding="utf-8"?>
<entry m:etag="W/"datetime'2020-04-29T02%3A01%3A19.0000000'"" xml:base="https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/ProductSet('HT-1060')</id>
<title type="text">ProductSet('HT-1060')</title>
<updated>2020-04-29T10:02:28Z</updated>
<category term="GWSAMPLE_BASIC.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="ProductSet('HT-1060')" rel="edit" title="Product"/>
<link href="ProductSet('HT-1060')/ToSalesOrderLineItems" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToSalesOrderLineItems" type="application/atom+xml;type=feed" title="ToSalesOrderLineItems"/>
<link href="ProductSet('HT-1060')/ToSupplier" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToSupplier" type="application/atom+xml;type=entry" title="ToSupplier"/>
<content type="application/xml">
<m:properties>
<d:ProductID>HT-1060</d:ProductID>
<d:TypeCode>PR</d:TypeCode>
<d:Category>Mice</d:Category>
In my API Management Proxy, I added the "ExtractVariable" policy that reads the "Category":
<ExtractVariables async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Source>response</Source>
<XMLPayload>
<Namespaces>
<Namespace prefix="d">http://schemas.microsoft.com/ado/2007/08/dataservices</Namespace>
</Namespaces>
<Variable name="ProductCategory">
<XPath>//d:Category</XPath>
</Variable>
</XMLPayload>
</ExtractVariables>
Note that you may need to fiddle around with the XPath expression a little as well as with the namespace.
As an alternative: if you need to do very specific things with the variable, you may want to to this in a JavaScript policy. Hence you could to an XML-to-JSON to start with, and then use the JavaScript policy to get the variable:
var payload = response.content.asJSON;
var productCategory = payload....Hope this helps!
Sven
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.