{ 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 /
  • General /
avatar image
6

Various uses of Assign Message Policy  

  • Export to PDF
sarthak created · Oct 02, 2015 at 11:44 PM · 10k Views · Dino-at-Google edited · Feb 19 at 05:20 PM

AssignMessage is an extremely diverse policy using which you can do a wide variety of things. There is good amount of descriptions on the AssignMessage documentation page but I am adding a few more here:

Set Up URL Redirections

<Set>
        <Headers>
            <Header name="Location">{config.protocol}://{config.organization}-{config.environment}.{config.domain}/web?access_token={access_token}</Header>
        </Headers>
        <StatusCode>302</StatusCode>
        <ReasonPhrase>Redirect</ReasonPhrase>
    </Set>

Setup multiple variables

This is needed if you want to setup a number of global variables at once to be referenced by other policies later in the pipeline.

    <AssignVariable>
        <Name>appSecret</Name>
        <Value>abcdedl1234</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>config.environment</Name>
        <Value>test</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>config.protocol</Name>
        <Value>https</Value>
    </AssignVariable>

CORS enable your APIs

Below is for CORS-Preflight

<Set>
     <Headers>
        <Header name="Access-Control-Allow-Origin">*</Header>
        <Header name="Access-Control-Allow-Methods">POST, GET, OPTIONS</Header>
        <Header name="Access-Control-Allow-Headers">Accept, Content-Type, Authorization, x-requested-with</Header>
        <Header name="Access-Control-Allow-Credentials">true</Header>
     </Headers>
</Set>

Setup a target url different than what is setup at target.xml.

Or also known as dynamic target. If based on a condition you need to manipulate the URL. You can do the same using javascript as well and javascript often adds more flexibility , but if the requirements are simple AssignMessage can do the trick as well.

<AssignVariable>
        <Name>target.url</Name>
        <Template>https://api.usergrid.com/orgName/sandbox/products/{myretail.productid}/has/reviews</Template>
    </AssignVariable>

Setting custom error messages

<Set>
        <Payload contentType="application/json">{
  "error": {
    "message" : "Not Found",
    "detail" : "The requested resource was not found."
} }
</Payload> <StatusCode>404</StatusCode> <ReasonPhrase>Not Found</ReasonPhrase> </Set>

If anyone has any other interesting use of the AssignMessage policy please add them in the comments.

thub.nodes.view.add-new-comment
policiesmessage logging policy
Add comment Show 3
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 Karthick Vankayala · May 29, 2016 at 02:19 PM 0
Link

Could you help me how to pass a custom header to back end using this policy if it permits?

My use case is I have created a KVM containing my App key. I want my proxy to inject this app key as a header to target request message.

Appreciate your help in advance!

avatar image Anil Sagar @ Google ♦♦ Karthick Vankayala   · May 29, 2016 at 02:24 PM 0
Link

@Karthick Vankayala ,

Welcome to Apigee Community.

You need to use KVM policy to retrieve the value from KVM & use Assign Message policy to set a header which will be sent to target in request flow. Have you tried something ? do you see any errors ? It should be straight forward. Keep us posted.

avatar image Rohan Jangid Anil Sagar @ Google ♦♦ · Feb 19 at 06:57 AM 0
Link

sir how can we display in body please have a look for proper documentation https://community.apigee.com/questions/90058/how-to-display-developer-details-when-ever-we-hit.html

Article

Contributors

avatar image avatar image avatar image

Follow this article

16 People are following this .

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

Navigation

Various uses of Assign Message Policy

Related Articles

Deep Dive: Creating an Apigee Java Callout Extension Policy

  • 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