Search code examples
xmlapigee

Extracting variables from XML in Apigee


While using Apigee i did a service callout to this URL "http://api.worldbank.org/countries/br" and i saved the content in "calloutResponse". So now calloutResponse should contain this:

> wb:countries xmlns:wb="http://www.worldbank.org" page="1" pages="1" per_page="50" total="1">
<wb:country id="BRA">
<wb:iso2Code>BR</wb:iso2Code>
<wb:name>Brazil</wb:name>
<wb:region id="LCN">Latin America & Caribbean (all income levels)</wb:region>
<wb:adminregion id="LAC">Latin America & Caribbean (developing only)</wb:adminregion>
<wb:incomeLevel id="UMC">Upper middle income</wb:incomeLevel>
<wb:lendingType id="IBD">IBRD</wb:lendingType>
<wb:capitalCity>Brasilia</wb:capitalCity>
<wb:longitude>-47.9292</wb:longitude>
<wb:latitude>-15.7801</wb:latitude>
</wb:country>
</wb:countries

>

I want to get the name "brazil" out of the object using the extract variable policy. So my code is this:

<ExtractVariables name="ExtractVariables4">
   <Source>calloutResponse.content</Source>
   <XMLPayload>
      <Namespaces>
        <Namespace prefix="dir">http://www.worldbank.org" page="1" pages="1" per_page="50" total="1</Namespace>
      </Namespaces>
      <Variable name="extraction" >
         <XPath>/dir:countries/dir:country/dir:name</XPath>
      </Variable>  
   </XMLPayload>
   <VariablePrefix>directionsresponse</VariablePrefix>
</ExtractVariables>

I can see in the trace that the calloutResponse.content is correctly uploaded but trying to get the name get me an error 500 with the body

"{"fault":"{\"detail\":{\"errorcode\":\"steps.extractvariables.ExecutionFailed\"},\"faultstring\":\"Failed to execute the ExtractVariables: ExtractVariables4\"}"}"

Can someone please help me whith this case?


Solution

  • Try specifying only calloutResponse - I don't think you need the ".content" part of the variable name.