{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
1
Question by veeraraghavendra · Feb 15, 2017 at 03:35 PM · 1.8k Views extractvariablesassign message policyenvironments

extracts variable from URI and assignmessage

Requirement:I want to fetch data from URI using Extract variables and display this as response using assign message.

I have created a proxy with no endpoint.Used 'Extract Variables-1' to extract from request url 'http://apitechbasics-prod.apigee.net/extractvarsample-uripath/vehicles/1234' and use assign message to display it as final response .I tried different ways ,but none of them worked .

Proxy:

<ProxyEndpoint name="default"> 
  <Description/> 
  <FaultRules/> 
  <PreFlow name="PreFlow"> 
    <Request> 
      <Step> 
        <Name>Extract-Variables-1</Name> 
      </Step> 
      <Step> 
        <Name>Assign-Message-1</Name> 
      </Step> 
    </Request> 
    <Response/> 
  </PreFlow> 
  <PostFlow name="PostFlow"> 
    <Request/> 
    <Response/> 
  </PostFlow> 
  <Flows/> 
  <HTTPProxyConnection> 
    <BasePath>/extractvarsample-uripath</BasePath> 
    <Properties/> 
    <VirtualHost>default</VirtualHost> 
    <VirtualHost>secure</VirtualHost> 
  </HTTPProxyConnection> 
  <RouteRule name="noroute"/> 
</ProxyEndpoint>

Extract Variables-1:

<ExtractVariables name="Extract-Variables-1"> 
  <DisplayName>EV-Extract Variables-URIPath</DisplayName> 
  <Properties/> 
  <Source>request</Source> 
  <URIPath> 
    <Pattern ignoreCase="true">/vehicles/{VIN}</Pattern> 
  </URIPath> 
  <VariablePrefix>pathurireq</VariablePrefix>
</ExtractVariables>

I am able to extract and put into 'pathurireq' but to display in response where I am facing issues.

Assign-Message-1:

<AssignMessage name="Assign-Message-1"> 
  <DisplayName>AM-Assign Message-URIPath</DisplayName> 
  <AssignVariable> 
    <Name>name</Name> 
    <Value/> 
    <Ref>pathurireq.id</Ref> 
  </AssignVariable> 
  <Set> 
    <Payload> 
      <Tamatar>{name}</Tamatar> 
      <Aloo>{name}</Aloo> 
    </Payload> 
  </Set> 
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> 
  <AssignTo createNew="false" transport="http" type="response"/> 
</AssignMessage>
Comment
Add comment Show 1
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dino ♦♦   · Feb 15, 2017 at 05:52 PM 0
Link

Just one comment - you can format the code you paste in by using the code button.

Click THAT, and THEN paste in the XML.

If you do that, then instead of this:

...we will all see something more readable, like this:

<ProxyEndpoint name="default"> 
  <Description/> 
  <FaultRules/> 
  <PreFlow name="PreFlow"> 
    <Request> 
      <Step> 
        <Name>Extract-Variables-1</Name> 
      </Step> 
      <Step> 
        <Name>Assign-Message-1</Name> 
      </Step> 
    </Request> 
    <Response/> 
  </PreFlow> 
  <PostFlow name="PostFlow"> 
    <Request/> 
    <Response/> 
  </PostFlow> 
  <Flows/> 
  <HTTPProxyConnection> 
    <BasePath>/extractvarsample-uripath</BasePath> 
    <Properties/> 
    <VirtualHost>default</VirtualHost> 
    <VirtualHost>secure</VirtualHost> 
  </HTTPProxyConnection> 
  <RouteRule name="noroute"/> 
</ProxyEndpoint>

I've modified your post to reformat the XML. But in the future, it would help if posters could do that on their own.

Close

1 Answer

  • Sort: 
avatar image
0
Best Answer

Answer by Dino   · Feb 15, 2017 at 05:58 PM

Two issues here.

1. you are assigning to the response message in the Request preflow.

The response message gets reset at inception of the Response flow, which happens AFTER the Request flow ends.

So you need to move your assignmessage to the response flow.

like this:

<ProxyEndpoint name="default"> 
  <Description/> 
  <FaultRules/> 
  <PreFlow name="PreFlow"> 
    <Request> 
      <Step> 
        <Name>Extract-Variables-1</Name> 
      </Step> 
    </Request> 
    <Response> 
      <Step> 
        <Name>Assign-Message-1</Name> 
      </Step> 
    </Response>
  </PreFlow> 
  <PostFlow name="PostFlow"> 
    <Request/> 
    <Response/> 
  </PostFlow> 
  <Flows/> 
  <HTTPProxyConnection> 
    <BasePath>/extractvarsample-uripath</BasePath> 
    <Properties/> 
    <VirtualHost>default</VirtualHost> 
    <VirtualHost>secure</VirtualHost> 
  </HTTPProxyConnection> 
  <RouteRule name="noroute"/> 
</ProxyEndpoint>

2. Your AssignMessage isn't quite right Modify it like so:

<AssignMessage name="Assign-Message-1"> 
  <Set> 
    <Payload contentType='text/xml'> 
      <Tamatar>{pathurireq.VIN}</Tamatar> 
      <Aloo>{pathurireq.VIN}</Aloo> 
    </Payload> 
  </Set> 
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> 
  <AssignTo createNew="false" transport="http" type="response"/> 
</AssignMessage>

The pathurireq is the prefix you have used in the ExtractVariables. And the VIN is the name for the field you are extracting. Hence the name of the variable you want to reference here is pathurireq.VIN . You should be able to use the Trace UI to verify that this variable has been set and holds the value you think it should hold.

Can you try that?

Comment
Add comment Show 4 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image veeraraghavendra · Feb 15, 2017 at 07:15 PM 0
Link

@Dino :Thanks for your response.

I am not able to extract variable from URI path 'http://apitechbasics-prod.apigee.net/extractvarsample-uripath/vehicles/1222'.Here is the policy that I have used .

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-Extract-Variables-URIPath">

<DisplayName>Extract Variables-1</DisplayName>

<Properties/>

<Source>request</Source>

<URIPath> <Pattern ignoreCase="true">/vehicles/{VIN}</Pattern> </URIPath>

<VariablePrefix>pathurireq</VariablePrefix>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

</ExtractVariables>

Please correct me ,if I did anything wrong.

avatar image Dino ♦♦ veeraraghavendra   · Feb 15, 2017 at 09:49 PM 0
Link

I don't know what you're doing wrong, but it works for me.

$ curl -i https://ORGNAME-ENVNAME.apigee.net/veeraraghavendra-1/vehicles/1276272
HTTP/1.1 200 OK
Date: Wed, 15 Feb 2017 21:47:45 GMT
Content-Type: text/xml
Content-Length: 65
Connection: keep-alive
Server: Apigee Router


<root><Tamatar>1276272</Tamatar><Aloo>1276272</Aloo></root>

See attached for a working API Proxy.

apiproxy-veeraraghavendra-1-20170215-135802.zip

ps: In the future, please be kind and format your XML when you paste it.

avatar image veeraraghavendra Dino ♦♦ · Feb 16, 2017 at 07:51 AM 0
Link

Many thanks @Dino,it is working now.

avatar image Preethi Ravichandran Dino ♦♦ · Feb 05, 2018 at 09:44 AM 0
Link

I can't download the zip file.

Follow this Question

Answers Answers and Comments

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to remove few fields from JSON array response? 2 Answers

How to Append dynamic request path to target end point based on request method. 1 Answer

How can i convert Xml data to Json and Json to Xml using Extract Variable or Assign Message Policy? 1 Answer

How to customize response of quota policy before it reaches limit ? 2 Answers

ExtractVariables returns "Unresolved variable : urielement.userID" 3 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges