Skip to Content
0
May 24, 2016 at 02:36 PM

Extract Variable from ODATA API

275 Views

Hello all,

I went through the very good guide from Holger in order to get started with HCP SAP APIM.

In order to create a custom dashboard, I would like to retrieve some information from the response of the SalesOrderSet resource, using an ExtractVariables policy, combined with a Statistics Collector Policy.

Here is the XML response I get for a specific SalesOrder:

<?xml version="1.0" encoding="utf-8"?>

<entry xml:base="https://SAPES4.SAPDEVCENTER.COM:443/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://SAPES4.SAPDEVCENTER.COM:443/sap/opu/odata/iwbep/GWSAMPLE_BASIC/SalesOrderSet('0500000000')</id>

<title type="text">SalesOrderSet('0500000000')</title>

<updated>2016-05-24T14:26:33Z</updated>

<category term="/IWBEP/GWSAMPLE_BASIC.SalesOrder" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

<link href="SalesOrderSet('0500000000')" rel="self" title="SalesOrder"/>

<link href="SalesOrderSet('0500000000')/ToBusinessPartner" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToBusinessPartner" type="application/atom+xml;type=entry" title="ToBusinessPartner"/>

<link href="SalesOrderSet('0500000000')/ToLineItems" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToLineItems" type="application/atom+xml;type=feed" title="ToLineItems"/>

<content type="application/xml">

<m:properties>

<d:SalesOrderID>0500000000</d:SalesOrderID>

To extract the SalesOrderID, I configured my ExtractVariables policy as follows:

<!-- Extract content from the request or response messages, including headers, URI paths, JSON/XML payloads, form parameters, and query parameters -->

<ExtractVariables async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>

<Source clearPayload="false">response</Source>

<VariablePrefix>SAP_APIM</VariablePrefix>

<XMLPayload stopPayloadProcessing="true">

<Namespaces>

<Namespace prefix="d">http://schemas.microsoft.com/ado/2007/08/dataservices</Namespace>

<Namespace prefix="m">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata</Namespace>

</Namespaces>

<Variable name="SalesOrderID" type="string">

<XPath>//d:SalesOrderID</XPath>

</Variable>

</XMLPayload>

</ExtractVariables>

However, when saving and updating the proxy, I get the following error message:

[Request ID: c27460bb-74f4-427f-a8b7-637f3be0db38]

Policy content for policy "SalesOrderID" is invalid. cvc-complex-type.2.4.d: Invalid content was found starting with element 'Namespace'. No child element is expected at this point.

IMHO, my policy is in line with the documentation SAP API Management

My workaround is pretty easy (XML-to-JSON, and then using a JPath) but I would like to see this working natively.

Thanks for any help!

Sven