Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Extract Variable from ODATA API

svenhuberti
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

  • SAP Managed Tags:
1 ACCEPTED SOLUTION

ElijahM
Advisor
Advisor
0 Kudos

Hi Sven,

At the risk of showing my ignorance in a public place as to XML and the like, it seems that cvc-complex-type.2.4.d is an XML schema validation issue (hence why JSON works).

If in fact you remove the namespaces, it will clear up the error (but you will now have the issue of creating an XPath to the element).

I believe this is an issue with the parser being quite strict, as I tried to same scenario with a simpler OData response (from http://api.openweathermap.org ) and was able to extract variable on a field (tested with country) successfully.

I know this doesn't totally help, but perhaps it can lead to some ideas of what to do next.

  • SAP Managed Tags:
1 REPLY 1

ElijahM
Advisor
Advisor
0 Kudos

Hi Sven,

At the risk of showing my ignorance in a public place as to XML and the like, it seems that cvc-complex-type.2.4.d is an XML schema validation issue (hence why JSON works).

If in fact you remove the namespaces, it will clear up the error (but you will now have the issue of creating an XPath to the element).

I believe this is an issue with the parser being quite strict, as I tried to same scenario with a simpler OData response (from http://api.openweathermap.org ) and was able to extract variable on a field (tested with country) successfully.

I know this doesn't totally help, but perhaps it can lead to some ideas of what to do next.

  • SAP Managed Tags: