AssignMessage policy

What

The Assign Message policy changes or creates new request and response messages during the API proxy Flow. The policy lets you perform the following actions on those messages:

  • Add new form parameters, headers, or query parameters to a message
  • Copy existing properties from one message to another
  • Remove headers, query parameteters, form parameters, and/or message payloads from a message
  • Set the value of existing properties in a message

With Assign Message, you typically add, change, or remove properties of either the request or response. However, you can also use Assign Message to create a custom request or response message and pass it to an alternative target, as described in Create custom request messages.

The Assign Message policy can create or change flow variables with the following child elements:

<AssignMessage> element

Defines an Assign Message policy.

Default Value See Default Policy tab, below
Required? Required
Type Complex object
Parent Element n/a
Child Elements <Add>
<AssignTo>
<AssignVariable>
<Copy>
<DisplayName>
<IgnoreUnresolvedVariables>
<Remove>
<Set>

The <AssignMessage> element uses the following syntax:

Syntax

The <AssignMessage> element uses the following syntax:

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <!-- All AssignMessage child elements are optional -->
  <Add>
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Add>

  <AssignTo createNew="[true|false]" transport="http"
    type="[request|response]">destination_variable_name</AssignTo>

  <AssignVariable>
    <Name>variable_name</Name>
    <Ref>source_variable</Ref>
    <Template>message_template</Template>
    <Value>variable_value</Value>
  </AssignVariable>

  <Copy source="[request|response]">
    <!-- Can also be an empty array (<FormParams/>) -->
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <!-- Can also be an empty array (<Headers/>) -->
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <Path>[false|true]</Path>
    <Payload>[false|true]</Payload>
    <!-- Can also be an empty array (<QueryParams/>) -->
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
    <ReasonPhrase>[false|true]</ReasonPhrase>
    <StatusCode>[false|true]</StatusCode>
    <Verb>[false|true]</Verb>
    <Version>[false|true]</Version>
  </Copy>

  <DisplayName>policy_display_name</DisplayName>

  <IgnoreUnresolvedVariables>[true|false]</IgnoreUnresolvedVariables>

  <Remove>
    <!-- Can also be an empty array (<FormParams/>) -->
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <!-- Can also be an empty array (<Headers/>) -->
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <Payload>[false|true]</Payload>
    <!-- Can also be an empty array (<QueryParams/>) -->
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Remove>

  <Set>
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <Path>path</Path>
    <Payload contentType="content_type" variablePrefix="prefix"
        variableSuffix="suffix">new_payload</Payload>
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
    <ReasonPhrase>reason_for_error or {variable}</ReasonPhrase>
    <StatusCode>HTTP_status_code or {variable}</StatusCode>
    <Verb>[GET|POST|PUT|PATCH|DELETE|{variable}]</Verb>
    <Version>[1.0|1.1|{variable}]</Verb>
  </Set>

</AssignMessage>

Default Policy

The following example shows the default settings when you add an Assign Message policy to your flow in the Edge UI:

<AssignMessage continueOnError="false" enabled="true" name="assign-message-default">
  <DisplayName>Assign Message-1</DisplayName>
  <Properties/>
  <Copy source="request">
    <Headers/>
    <QueryParams/>
    <FormParams/>
    <Payload/>
    <Verb/>
    <StatusCode/>
    <ReasonPhrase/>
    <Path/>
  </Copy>
  <Remove>
    <Headers>
      <Header name="h1"/>
    </Headers>
    <QueryParams>
      <QueryParam name="q1"/>
    </QueryParams>
    <FormParams>
      <FormParam name="f1"/>
    </FormParams>
    <Payload/>
  </Remove>
  <Add>
    <Headers/>
    <QueryParams/>
    <FormParams/>
  </Add>
  <Set>
    <Headers/>
    <QueryParams/>
    <FormParams/>
    <!-- <Verb>GET</Verb> -->
    <Path/>
  </Set>
  <AssignVariable>
    <Name>name</Name>
    <Value/>
    <Ref/>
  </AssignVariable>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

When you insert a new Assign Message policy in the Edge UI, the template contains stubs for all possible operations. Typically, you select which operation(s) you want to perform with this policy and remove the rest of the child elements. For example, if you want to perform a copy operation, use the <Copy> element and remove <Add>, <Remove>, and other child elements from the policy to make it more readable.

This element has the following attributes that are common to all policies:

Attribute Default Required? Description
name N/A Required

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

continueOnError false Optional Set to "false" to return an error when a policy fails. This is expected behavior for most policies. Set to "true" to have flow execution continue even after a policy fails.
enabled true Optional Set to "true" to enforce the policy. Set to "false" to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.
async  not_interested false Deprecated This attribute is deprecated.

The following table provides a high-level description of the child elements of <AssignMessage>:

Child Element Required? Description
Common operations
<Add> Optional Adds information to the message object that is specified by the <AssignTo> element.

<Add> adds headers or parameters to the message that don't exist in the original message. To overwrite existing headers or parameters, use the <Set> element.

<Copy> Optional Copies information from the message specified by the source attribute to the message object specified by the <AssignTo> element.
<Remove> Optional Deletes the specified elements from the message variable specified in the <AssignTo> element.
<Set> Optional Replaces values of existing properties on the request or response, which is specified by the <AssignTo> element.

<Set> overwrites headers or parameters that already exist in the original message. To add new headers or parameters, use the <Add> element.

Other child elements
<AssignTo> Optional Specifies which message the Assign Message policy operates on. This can be the standard request or response, or it can be a new, custom message.
<AssignVariable> Optional Assigns a value to a flow variable. If the variable does not exist, then <AssignVariable> creates it.
<IgnoreUnresolvedVariables> Optional Determines whether processing stops when an unresolved variable is encountered.

Each of these child elements is described in the sections that follow.

Examples

The following examples show some of the ways in which you can use the Assign Message policy:

1: Add header

The following example adds a header to the request with the <Add> element:

<AssignMessage continueOnError="false" enabled="true" name="add-headers-1">
  <Add>
    <Headers>
      <Header name="user-agent">{request.user.agent}</Header>
    </Headers>
  </Add>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

2: Remove payload

The following example deletes the payload from the response with the <Remove> element:

<AssignMessage continueOnError="false" enabled="true" name="remove-1">
  <DisplayName>remove-1</DisplayName>
  <Remove>
    <Payload>true</Payload>
  </Remove>
  <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

3: Modify response

The following example modifies an existing response object by adding a header to it:

<AssignMessage name="modify-response">
  <Set>
    <Headers>
      <Header name="Cache-Hit">{lookupcache.LookupCache-1.cachehit}</Header>
    </Headers>
  </Set>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" type="response"></AssignTo>
</AssignMessage>

This example does not create a new message. Instead, it modifies an existing response message by adding an HTTP header.

Because this example omits a variable name in the <AssignTo> element, and specifies type as "response", this policy modifies the response object returned by the target server.

The HTTP header added to the response message by this policy is derived from a variable populated by the LookupCache policy. Therefore the response message modified by this Assign Message policy contains an HTTP header that indicates whether the results have been pulled from the cache or not. Setting headers in the response can be handy for debugging and troubleshooting.

4: Set dynamic content

You can use Assign Message to embed dynamic content in the payload of response and request messages.

To embed Edge flow variables in an XML payload, wrap the designated variable in curly braces, like this: {prefix.name}.

The following example embeds the value of the user-agent HTTP header flow variable in an XML element called User-agent:

<AssignMessage name="set-dynamic-content">
  <AssignTo createNew="false" type="response"></AssignTo>
  <Set>
    <Payload contentType="text/xml">
      <User-agent>{request.header.user-agent}</User-agent>
    </Payload>
  </Set>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</AssignMessage>

For JSON payloads, you can insert variables using the variablePrefix and variableSuffix attributes with delimiter characters as shown in the following example:

<AssignMessage name="set-payload">
  <Payload contentType="application/json" variablePrefix="@" variableSuffix="#">
  {
     "user-agent": "@request.header.user-agent#"
  }
  </Payload>
</AssignMessage>

For a complete list of flow variables, see Flow variables reference.

As of cloud release 16.08.17, you can also use curly braces to insert variables.

5: Remove query param

The following example removes the apikey query parameter from the request:

<AssignMessage name="remove-query-param">
  <Remove>
    <QueryParams>
      <QueryParam name="apikey"/>
    </QueryParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

It's a best practice to strip the apikey query parameter from the request message when you use the VerifyAPIKey policy for user authentication. You do this to prevent sensitive key information from being passed to the backend target.

6: Set/get variables

The following example uses three Assign Message policies:

  1. Creates three flow variables in the request, with static values
  2. Gets the flow variables dynamically in a second policy in the request flow
  3. Sets them in the payload of the response
<!-- Policy #1: Set variables in the request -->
<AssignMessage continueOnError="false" enabled="true" name="set-variables">
    <!-- Create a variable named myAppSecret -->
    <AssignVariable>
        <Name>myAppSecret</Name>
        <Value>42</Value>
    </AssignVariable>
    <!-- Create a variable named config.environment -->
    <AssignVariable>
        <Name>config.environment</Name>
        <Value>test</Value>
    </AssignVariable>
    <!-- Create a variable named config.protocol -->
    <AssignVariable>
        <Name>config.protocol</Name>
        <Value>gopher</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

In the first policy, the <AssignVariable> element creates and sets three variables in the request. Each <Name> element specifies a variable name, and <Value> specifies the value.

The second policy uses the <AssignVariable> element to read in the values and creates three new variables:

<!-- Policy #2: Get variables from the request -->
<AssignMessage continueOnError="false" enabled="true" name="get-variables">
  <AssignTo createNew="false" transport="http" type="request"/>
  <!-- Get the value of myAppSecret and create a new variable, secret -->
  <AssignVariable>
    <Name>secret</Name>
    <Ref>myAppSecret</Ref>
    <Value>0</Value>
  </AssignVariable>
  <!-- Get the value of config.environment and create a new variable, environment -->
  <AssignVariable>
    <Name>environment</Name>
    <Ref>config.environment</Ref>
    <Value>default</Value>
  </AssignVariable>
  <!-- Get the value of config.protocol and create a new variable, protocol -->
  <AssignVariable>
    <Name>protocol</Name>
    <Ref>config.protocol</Ref>
    <Value>default</Value>
  </AssignVariable>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

In the second policy, the <Ref> element references the source variable, and <Name> elements specify the names of the new variables. If the variable referenced by the <Ref> element is not accessible, you can use the value specified by the <Value> element.

To try out this set of policies:

  1. Add policies #1 and #2 to the request flow. Be sure to put policy #1 before policy #2.
  2. Add the third policy in the response flow.
  3. The third policy uses the <Set> element to add the variables to the response. The following example constructs an XML payload in the response that Edge returns to the client:
    <!-- Policy #3: Add variables to the response -->
    <AssignMessage continueOnError="false" enabled="true" name="put-em-in-the-payload">
      <DisplayName>put-em-in-the-payload</DisplayName>
      <Set>
        <Payload contentType="application/xml">
          <wrapper>
            <secret>{secret}</secret>
            <config>
              <environment>{environment}</environment>
              <protocol>{protocol}</protocol>
            </config>
          </wrapper>
        </Payload>
      </Set>
      <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
      <AssignTo createNew="false" transport="http" type="response"/>
    </AssignMessage>
    

    Note that the syntax to access flow variables in <Set> is to wrap them in curly braces.

    Be sure to set the <Payload> element's contentType attribute to "application/xml".

  4. Send a request to your API proxy; for example:
    curl -vL https://ahamilton-eval-test.apigee.net/myproxy

    Optionally, you can pipe the results through a utility such as xmllint so that the XML is displayed in a nicely formatted structure:

    curl -vL https://ahamilton-eval-test.apigee.net/myproxy | xmllint --format -

    The body of the response should look like the following:

    <wrapper>
      <secret>42</secret>
      <config>
        <environment>test</environment>
        <protocol>gopher</protocol>
      </config>
    </wrapper>

7: Get Service Callout response headers

In the following example, let's say that a ServiceCallout policy is in the API proxy request, and the callout response contains multiple headers of the same name (Set-Cookie). Assuming the Service Callout's response variable is the default calloutResponse, the following policy gets the second Set-Cookie header value.

<AssignMessage continueOnError="false" enabled="true" name="get-header">
  <Set>
    <Payload contentType="application/json">
      {"Cookies from Service Callout":" {calloutResponse.header.Set-Cookie.2}"}
    </Payload>
  </Set>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

To list all header values, use the following variable instead:

{calloutResponse.header.Set-Cookie.values}

Each child element in this reference has additional examples. For even more examples, see AssignMessage example on GitHub.

Child element reference

This section describes the child elements of <AssignMessage>.

<Add>

Adds information to the request or response, which is specified by the <AssignTo> element.

The <Add> element adds new properties on the message that don't exist in the original message. To change the values of existing properties, use the <Set> element.

Default Value n/a
Required? Optional
Type Complex type
Parent Element <AssignMessage>
Child Elements <FormParams>
<Headers>
<QueryParams>

The <Add> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Add>
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Add>
</AssignMessage>

Example 1

The following example uses the <FormParams> element to get the values of three query string parameters from the initial request and set them as form parameters on the target endpoint request:

<AssignMessage continueOnError="false" enabled="true" name="add-formparams-3">
  <Add>
    <FormParams>
      <FormParam name="name">{request.queryparam.name}</FormParam>
      <FormParam name="zip">{request.queryparam.zipCode}</FormParam>
      <FormParam name="lang">{request.queryparam.lang}</FormParam>
    </FormParams>
  </Add>
  <AssignTo transport="http" type="request"/>
</AssignMessage>

Example 2

The following example uses the <Headers> element to add the User-Agent header to the target endpoint request:

<AssignMessage continueOnError="false" enabled="true" name="add-headers-1">
  <Add>
    <Headers>
      <Header name="user-agent">{request.user.agent}</Header>
    </Headers>
  </Add>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Example 3

The following example uses the <QueryParams> element to add a single query parameter with a static value to the request:

<AssignMessage continueOnError="false" enabled="true" name="add-queryparams-1">
  <Add>
    <QueryParams>
      <QueryParam name="myParam">42</QueryParam>
    </QueryParams>
  </Add>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

This example uses <Add> in the request preflow. If you look at the results in a tool such as the Trace tool, the request to "http://httpbin.org/get" becomes "http://httpbin.org/get?myParam=42".

The child elements of <Add> support dynamic string substitution, known as message templating.

<FormParams> (child of <Add>)

Adds new form parameters to the request message. This element has no effect on a response message.

Default Value n/a
Required? Optional
Type Array of <FormParam> elements
Parent Element <Add>
Child Elements <FormParam>

The <FormParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Add>
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
  <AssignTo createNew="[true|false]" transport="http"
    type="[request|response]">destination_variable_name</AssignTo>
  </Add>
</AssignMessage>

Example 1

The following example adds a single form parameter ("answer") and a static value ("42") to the request:

<AssignMessage continueOnError="false" enabled="true" name="add-formparams-1">
  <Add>
    <FormParams>
      <FormParam name="answer">42</FormParam>
    </FormParams>
  </Add>
  <AssignTo transport="http" type="request"></AssignTo>
</AssignMessage>

Example 2

The following example gets the value of the name query string parameter and adds it to the request as a form parameter:

<AssignMessage continueOnError="false" enabled="true" name="add-formparams-2">
  <Add>
    <FormParam name="name">{request.queryparam.name}</FormParam>
  </Add>
</AssignMessage>

Note that this example does not specify a target with <AssignTo>. This policy adds the parameter to the request only.

Example 3

The following example adds multiple form parameters to the request:

<AssignMessage continueOnError="false" enabled="true" name="add-formparams-3">
  <Add>
    <FormParams>
      <FormParam name="name">{request.queryparam.name}</FormParam>
      <FormParam name="zip">{request.queryparam.zipCode}</FormParam>
      <FormParam name="lang">{request.queryparam.lang}</FormParam>
    </FormParams>
  </Add>
  <AssignTo transport="http" type="request"/>
</AssignMessage>

This example gets the query string parameters from the originating request and adds them as form parameters to the request sent to the target endpoint.

You can use the Trace tool to look at the flow. You'll see that the body of the request contains the URL-encoded form data, which was originally passed in as query string parameters:

%7Busername%7D=nick&%7Bzip_code%7D=90210&%7Bdefault_language%7D=en

You can use <FormParams> only when the following criteria are met:

  • HTTP verb: POST
  • Message type: Request
  • One (or both) of the following:
    • Form data: Set to some value, or "" (the empty string). For example, with curl, add -d "" to your request.
    • Content-Length header: Set to 0 (if no data is in the original request; otherwise, the current length, in bytes). For example, with curl add -H "Content-Length: 0" to your request.

For example:

curl -vL -X POST -d "" -H "Content-Type: application/x-www-form-urlencoded"
  https://ahamilton-eval-test.apigee.net/am-test

When you add <FormParams>, Edge sets the request's Content-Type header to "application/x-www-form-urlencoded" before sending the message to the target service.

<Headers> (child of <Add>)

Adds new headers to the specified request or response, which is specified by the <AssignTo> element.

Default Value n/a
Required? Optional
Type Array of <Header> elements
Parent Element <Add>
Child Elements <Header>

The <Headers> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Add>
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
  </Add>
</AssignMessage>

Example 1

The following example adds the user-agent header to the request message, and assigns the value of the request.user.agent flow variable to that header.

<AssignMessage continueOnError="false" enabled="true" name="add-headers-1">
  <Add>
    <Headers>
      <Header name="user-agent">{request.user.agent}</Header>
    </Headers>
  </Add>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

<QueryParams> (child of <Add>)

Adds new query parameters to the request. This element has no effect on a response.

Default Value n/a
Required? Optional
Type Array of <QueryParam> elements
Parent Element <Add>
Child Elements <QueryParam>

The <QueryParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Add>
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Add>
</AssignMessage>

Example 1

The following example adds the query parameter "myParam" to the request and assigns the value "42" to it:

<AssignMessage continueOnError="false" enabled="true" name="add-queryparams-1">
  <Add>
    <QueryParams>
      <QueryParam name="myParam">42</QueryParam>
    </QueryParams>
  </Add>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

You can use <QueryParams> only when the following criteria are met:

  • HTTP verb: GET
  • Message type: Request

In addition, you can only set query parameters when the <AssignTo> element's type attribute is a request message. Setting them on the response has no effect.

If you define an empty array of query parameters in your policy (<Add><QueryParams/></Add>), the policy does not add any query parameters. This is the same as omitting <QueryParams>.

<AssignTo>

Determines which object the Assign Message policy operates on. The options are:

  • Request message: The request received by the API proxy
  • Response message: The response returned from the target server
  • Custom message: A custom request or response object

Note that in some cases, you cannot change the object on which the Assign Message policy acts. For example, you cannot use <Add> or <Set> to add or change query parameters (<QueryParams>) or form parameters (<FormParams>) on the response. You can only manipulate query parameters and form parameters on the request.

Default Value n/a
Required? Optional
Type String
Parent Element <AssignMessage>
Child Elements None

If you do not specify <AssignTo>, the policy acts on the default request or response, which is based on where the policy executes. If the policy executes in the request flow, it affects the request message. If it executes in the response flow, the policy affects the response by default.

The <AssignTo> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <AssignTo createNew="[true|false]" transport="http"
    type="[request|response]">destination_variable_name</AssignTo>
</AssignMessage>

Example 1

The following example specifies that the target is the original request that will be sent to the target endpoint:

<AssignMessage name="assignto-1">
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

By setting createNew to "false" (the default), this example does not create a new request. All operations in this policy affect the original request.

Example 2

The following example creates a new request object:

<AssignMessage name="assignto-2">
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

When you create a new request or response object, the other elements of the Assign Message policy (such as <Add>, <Set>, and <Set>) act on that new request object.

You can access the new request object in other policies later in the flow, or send the new request object to an external service with a ServiceCallout policy.

Example 3

The following example creates a new request object named "MyRequestObject":

<AssignMessage name="assignto-2">
  <AssignTo createNew="true" transport="http" type="request"&gt;MyRequestObject&lt;/AssignTo>
</AssignMessage>

When you create a new request or response object, the other elements of the Assign Message policy (such as <Add>, <Set>, and <Set>) act on that new request object.

You can access the new request object in other policies later in the flow, or send the new request object to an external service with a ServiceCallout policy.

The following table describes the attributes of <AssignTo>:

Attribute Description Required? Type
createNew

Determines whether this policy creates a new message when assigning values.

If "true", then the policy creates a new variable of the type specified by type (either "request" or "response"). If you do not specify the name of the new variable, then the policy creates a new request or response object, based on the value of type.

If "false", then the policy responds in one of two ways:

  • If <AssignTo> can resolve the variable name to a request or response, then it continues processing. For example, if the policy is in a request flow, the variable is the request object. If the policy is in a response, the variable is the response object.
  • If <AssignTo> cannot be resolved, or resolves to a non-message type, then the policy throws an error.

If createNew is not specified, the policy responds in one of two ways:

  • If <AssignTo> resolves to a message, then processing advances to the next step.
  • If <AssignTo> cannot be resolved, or resolves to a non-message type, a new variable of type specified in type is created.
Optional Boolean
transport

Specifies the transport type for the request or response message type.

The default value is "http" (the only supported value).

Optional String
type Specifies the type of the new message, when createNew is "true". Valid values are "request" or "response".

The default value is "request". If you omit this attribute, then Edge creates either a request or a response, depending on where in the flow this policy executes.

Optional String

<AssignVariable>

Assigns a value to a destination flow variable (e.g., a variable whose value is set by the Assign Message policy). If the flow variable does not exist, then <AssignVariable> creates it.

Default Value n/a
Required? Optional
Type Complex type
Parent Element <AssignMessage>
Child Elements <Name> (required)
<Ref>
<Template>
<Value>

The value that you assign to the destination flow variable can be one of the following:

  • Literal string: Use the <Value> child element to specify a literal string value for the destination flow variable.
  • Flow variable: Use the <Ref> child element to specify the value of an existing flow variable for the destination flow variable. For a complete list of flow variables that can be used as a source, see Flow variables reference.
  • Message template: Use the <Template> child element to specify a message template for the destination flow variable.

The <AssignVariable> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <AssignVariable>
    <Name>variable_name</Name>
    <Ref>source_variable</Ref>
    <Template>message_template</Template>
    <Value>variable_value</Value>
  </AssignVariable>
</AssignMessage>

Use the <Ref> element to specify the source variable. If the variable referenced by <Ref> is not accessible, Edge uses the value specified by the <Value> element. If you define <Template>, it takes precedence over the other child elements.

Example 1

The following example sets the value of a new variable, myvar, to the literal value "42":

<AssignMessage name="assignvariable-1">
  <AssignVariable>
    <Name>myvar</Name>
    <Value>42</Value>
  </AssignVariable>
</AssignMessage>

Example 2

The following example assigns the value of the flow variable request.header.user-agent to the destination flow variable myvar and the value of the query parameter country to the destination flow variable Country:

<AssignMessage name="assignvariable-2">
  <AssignVariable>
    <Name>myvar</Name>
    <Ref>request.header.user-agent</Ref>
    <Value>ErrorOnCopy</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>Country</Name>
    <Ref>request.queryparam.country</Ref>
    <Value>ErrorOnCopy</Value>
  </AssignVariable>
</AssignMessage>

If either assignment fails, Edge instead assigns the value "ErrorOnCopy" to the destination flow variable.

If the myvar or Country flow variables do not exist, <AssignVariable> creates them.

Example 3

The following example uses the <Template> child element to concatenate two context variables with a literal string (a hyphen) between them:

<AssignMessage name='template-1'>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>my_destination_variable</Name>
    <Value>BADDBEEF</Value>
    <Template>{system.uuid}-{messageid}</Template>
  </AssignVariable>
</AssignMessage>

A common use for <AssignVariable> is to set a default value for a query parameter, header, or other value that can be passed in with the request. You do this with a combination of both the <Ref> and <Value> child elements. For more information, see the examples for <Ref>.

<Name> (child of <AssignVariable>)

Specifies the name of the destination flow variable (e.g., the variable whose value is set by the Assign Message policy). If the variable named in <AssignVariable> does not exist, the policy creates one with that name.

Default Value n/a
Required? Required
Type String
Parent Element <AssignVariable>
Child Elements None

The <Name> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <AssignVariable>
    <Name>variable_name</Name>
  </AssignVariable>
</AssignMessage>

Example 1

The following example specifies the destination variable as myvar, and sets it to the literal value "42":

<AssignMessage name="assignvariable-1">
  <AssignVariable>
    <Name>myvar</Name>
    <Value>42</Value>
  </AssignVariable>
</AssignMessage>

If myvar does not exist, <AssignVariable> creates it.

<Ref> (child of <AssignVariable>)

Specifies the source of the assignment as a flow variable. The flow variable can be one of the pre-defined flow variables (as listed in the Flow variables reference), or a custom flow variable that you created.

The value of <Ref> is always interpreted as a flow variable; you cannot specify a literal string as the value. To assign a literal string value, use the <Value> element instead.

Default Value n/a
Required? Optional
Type String
Parent Element <AssignVariable>
Child Elements None

When you specify a flow variable with <Ref>, omit the enclosing brackets "{}" that you would normally use to reference a flow variable. For example, to set the value of your new variable to the value of the client.host flow variable:

Do this (no brackets):
  <Ref>client.host</Ref>

Do NOT do this (brackets):
  <Ref>{client.host}</Ref>

To define a default value for the destination flow variable, use <Value> in combination with <Ref>. If the flow variable specified by <Ref> does not exist, cannot be read, or is null, then Edge assigns the value of <Value> to the destination flow variable instead.

The <Ref> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <AssignVariable>
    <Name>variable_name</Name>
    <Ref>source_variable</Ref>
  </AssignVariable>
</AssignMessage>

Example 1

The following example assigns the value of the flow variable request.header.user-agent to the destination flow variable myvar and the value of the query parameter country to the Country variable:

<AssignMessage name="assignvariable-4">
  <AssignVariable>
    <Name>myvar</Name>
    <Ref>request.header.user-agent</Ref>
  </AssignVariable>
  <AssignVariable>
    <Name>Country</Name>
    <Ref>request.queryparam.country</Ref>
  </AssignVariable>
</AssignMessage>

In this example, Edge does not have a default (or fallback value) specified for either assignment.

Example 2

The following example assigns the value of the flow variable request.header.user-agent to the destination flow variable myvar and the value of the query parameter country to the Country variable:

<AssignMessage name="assignvariable-2">
  <AssignVariable>
    <Name>myvar</Name>
    <Ref>request.header.user-agent</Ref>
    <Value>ErrorOnCopy</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>Country</Name>
    <Ref>request.queryparam.country</Ref>
    <Value>ErrorOnCopy</Value>
  </AssignVariable>
</AssignMessage>

In this example, if the values of the request.header.user-agent flow variable or the Country query parameter are null, unreadable, or malformed, Edge assigns the value "ErrorOnCopy" to the new variables.

Example 3

A common use case for <AssignVariable> is to set the default value of a query parameter, header, or other value that can be passed in with the request. For example, you create a weather API proxy where the request takes a single query parameter named "w". This parameter contains the ID of the city for which you want the weather. The request URL has the form:

http://myCO.com/v1/weather/forecastrss?w=city_ID

To define a default value for "w", create an Assign Message policy like the following:

<AssignMessage continueOnError="false" enabled="true" name="assignvariable-3">
  <AssignTo createNew="false" transport="http" type="request"/>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>request.queryparam.w</Name>
    <Ref>request.queryparam.w</Ref>
    <Value>12797282</Value>
  </AssignVariable>
</AssignMessage>

In this example, <AssignVariable> gets the value of request.queryparam.w and assigns it to itself. If the flow variable is null, meaning the "w" query parameter was omitted from the request, then this example uses the default value from the <Value> element. Therefore, you can make a request to this API proxy that omits the "w" query parameter:

http://myCO.com/v1/weather/forecastrss

...and still have the API proxy return a valid result.

Unlike when using <Value>, the value of <Ref> must be a flow variable, such as a property of a request, response, or target object. The value can also be a custom flow variable that you created.

If you specify a flow variable that does not exist for the value of <Ref>, and the value of <IgnoreUnresolvedVariables> is "true", Edge throws an error.

<Template> (child of <AssignVariable>)

Specifies the source of the assignment as a message template. This means that you can combine literal strings with variable names wrapped in curly braces in the value of the <Template> element. In addition, message templates support functions such as escaping and case conversion.

Default Value n/a
Required? Optional
Type String
Parent Element <AssignVariable>
Child Elements None

The <Template> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <AssignVariable>
    <Template>message_template</Template>
  </AssignVariable>
</AssignMessage>

Example 1

The following example uses message templating syntax to concatenate two context variables with a literal string (a hyphen) between them:

<AssignMessage name='template-1'>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>my_destination_variable</Name>
    <Value>BADDBEEF</Value>
    <Template>{system.uuid}-{messageid}</Template>
  </AssignVariable>
</AssignMessage>

<Value> (child of <AssignVariable>)

Defines the value of the destination flow variable set with <AssignVariable>. The value is always interpreted as a literal string; you cannot use a flow variable as the value, even if you wrap the value in brackets ("{}"). To use a flow variable, use <Ref> instead.

Default Value n/a
Required? Optional
Type String
Parent Element <AssignVariable>
Child Elements None

When used in combination with the <Ref> element, <Value> acts as the default (or fallback) value. If <Ref> is not specified, is unresolvable, or is null, the value of <Value> is used.

The <Value> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <AssignVariable>
    <Name>variable_name</Name>
    <Value>variable_value</Value>
  </AssignVariable>
</AssignMessage>

Example 1

The following example sets the value of the destination flow variable, myvar, to the literal value "42":

<AssignMessage name="assignvariable-1">
  <AssignVariable>
    <Name>myvar</Name>
    <Value>42</Value>
  </AssignVariable>
</AssignMessage>

Example 2

The following example assigns the value of the flow variable request.header.user-agent to the flow variable myvar and the value of the query parameter country to the Country variable:

<AssignMessage name="assignvariable-2">
  <AssignVariable>
    <Name>myvar</Name>
    <Ref>request.header.user-agent</Ref>
    <Value>ErrorOnCopy</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>Country</Name>
    <Ref>request.queryparam.country</Ref>
    <Value>ErrorOnCopy</Value>
  </AssignVariable>
</AssignMessage>

If either assignment fails, <AssignVariable> instead assigns the value "ErrorOnCopy" to the destination flow variable.

<Copy>

Copies values from the message specified by the source attribute to the message specified by the <AssignTo> element. If you do not specify a target with <AssignTo>, then this policy copies the values to the request or response, depending on where in the flow this policy executes.

Default Value n/a
Required? Optional
Type String
Parent Element <AssignVariable>
Child Elements <FormParams>
<Headers>
<Path>
<Payload>
<QueryParams>
<ReasonPhrase>
<StatusCode>
<Verb>
<Version>

The <Copy> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
    <Copy source="[request|response]">
    <!-- Can also be an empty array (<FormParams/>) -->
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <!-- Can also be an empty array (<Headers/>) -->
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <Path>[false|true]</Path>
    <Payload>[false|true]</Payload>
    <!-- Can also be an empty array (<QueryParams/>) -->
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
    <ReasonPhrase>[false|true]</ReasonPhrase>
    <StatusCode>[false|true]</StatusCode>
    <Verb>[false|true]</Verb>
    <Version>[false|true]</Version>
  </Copy>
  <!-- Used as the destination for the <Copy> values -->
  <AssignTo createNew="[true|false]" transport="http"
    type="[request|response]">destination_variable_name</AssignTo>
</AssignMessage>
  

Example 1

The following example copies a header, three form parameters, the path, and all query parameters from the request to a new, custom request:

<AssignMessage continueOnError="false" enabled="true" name="copy-1">
  <Copy source="request">
    <Headers>
      <Header name="Header_Name_1">Header value 1</Header>
    </Headers>
    <FormParams>
      <FormParam name="Form_Param_Name_1">Form param value 1</FormParam>
      <FormParam name="Form_Param_Name_2">Form param value 1</FormParam>
      <FormParam name="Form_Param_Name_3">Form param value 1</FormParam>
    </FormParams>
    <Payload>false</Payload>
    <Path>true</Path>
    <QueryParams/>
    <ReasonPhrase>false</ReasonPhrase>
    <StatusCode>false</StatusCode>
    <Verb>false</Verb>
    <Version>false</Version>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

The <Copy> element has the following attributes:

Attribute Description Required? Type
source

Specifies the source object of the copy.

  • If source is not specified, it is treated as a simple message. For example, if the policy is in the request flow, then the source defaults to the request object. If the policy is in the response flow, it defaults to the response object. If you omit source, you can use an absolute reference to a flow variable as the source of the copy. For example, specify the value as {request.header.user-agent}.
  • If the source variable cannot be resolved, or resolves to a non-message type, <Copy> fails to respond.
Optional String

<FormParams> (child of <Copy>)

Copies form parameters from the request specified by the <Copy> element's source attribute to the request specified by the <AssignTo> element. This element has no effect on a response.

Default Value n/a
Required? Optional
Type Array of <FormParam> elements or an empty array
Parent Element <Copy>
Child Elements <FormParam>

The <FormParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <!-- Can also be an empty array (<FormParams/>) -->
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
  </Copy>
</AssignMessage>

Example 1

The following example copies a single form parameter from the request to the custom request "MyCustomRequest":

<AssignMessage name="copy-formparams-1">
  <Copy source="request">
    <FormParams>
      <FormParam name="paramName">Form param value 1</FormParam>
    </FormParams>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 2

The following example copies all form parameters to the custom request "MyCustomRequest":

<AssignMessage name="copy-formparams-2">
  <Copy source="request">
    <FormParams/>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 3

The following example copies three form parameters to the custom request "MyCustomRequest":

<AssignMessage name="copy-formparams-3">
  <Copy source="request">
    <FormParams>
      <FormParam name="paramName1"/>
      <FormParam name="paramName2"/>
      <FormParam name="paramName3"/>
    </FormParams>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 4

If there are multiple form params with the same name, use the following syntax:

<AssignMessage name="copy-formparams-4">
  <Copy source="request">
    <FormParams>
      <FormParam name="f1"/>
      <FormParam name="f2"/>
      <FormParam name="f3.2"/>
    </FormParams>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

This example copies "f1", "f2", and the second value of "f3". If "f3" has only one value, then it is not copied.

You can use <FormParams> only when the following criteria are met:

  • HTTP verb: POST
  • Message type: Response
  • One (or both) of the following:
    • Form data: Set to some value, or "" (the empty string). For example, with curl, add -d "" to your request.
    • Content-Length header: Set to 0 (if no data is in the original request; otherwise, the current length. For example, with curl add -H "Content-Length: 0" to your request.

When you copy <FormParams>, <Copy> sets the message's Content-Type to "application/x-www-form-urlencoded" before sending the message to the target service.

<Headers> (child of <Copy>)

Copies HTTP headers from the request or response message specified by the <Copy> element's source attribute to the request or response message specified by the <AssignTo> element.

Default Value n/a
Required? Optional
Type An array of <Header> elements or an empty array
Parent Element <Copy>
Child Elements <Header>

The <Headers> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <!-- Can also be an empty array (<Headers/>) -->
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
  </Copy>
</AssignMessage>

Example 1

The following example copies the user-agent header from the request to the new, custom request object:

<AssignMessage name="copy-headers-1">
  <Copy source="request">
    <Headers>
      <Header name="user-agent"/>
    </Headers>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 2

To copy all headers, use an empty <Headers> element, as the following example shows:

<AssignMessage name="copy-headers-2">
  <Copy source="request">
    <Headers/>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 3

If there are multiple headers with the same name, use the following syntax:

<AssignMessage name="copy-headers-3">
  <Copy source="request">
    <Headers>
      <Header name="h1"/>
      <Header name="h2"/>
      <Header name="h3.2"/>
    </Headers>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

This example copies "h1", "h2", and the second value of "h3". If "h3" has only one value, then it is not copied.

<Path> (child of <Copy>)

Determines whether the path should be copied from the source request to the destination request. This element has no effect on a response.

If "true", this policy copies the path from the request message specified by the <Copy> element's source attribute to the request message specified by the <AssignTo> element.

Default Value False
Required? Optional
Type Boolean
Parent Element <Copy>
Child Elements None

The <Path> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <Path>[false|true]</Path>
  </Copy>
</AssignMessage>

Example 1

The following example indicates that Assign Message should copy the path from the source request to the new, custom request object:

<AssignMessage name="copy-path-1">
  <Copy source="request">
    <Path>true</Path>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

You can use <Path> only when the following criteria are met:

  • Message type: Request

<Payload> (child of <Copy>)

Determines whether the payload should be copied from the source to the destination. The source and destination can be requests or responses.

If "true", this policy copies the payload from the message specified by the <Copy> element's source attribute to the message specified by the <AssignTo> element.

Default Value False
Required? Optional
Type Boolean
Parent Element <Copy>
Child Elements None

The <Payload> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <Payload>[false|true]</Payload>
  </Copy>
</AssignMessage>

Example 1

The following example sets <Payload> to "true" so that the request payload is copied from the request to the response:

<AssignMessage name="copy-payload-1">
  <Copy source="request">
    <Payload>true</Payload>
  </Copy>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

<QueryParams> (child of <Copy>)

Copies query string parameters from the request specified by the <Copy> element's source attribute to the request specified by the <AssignTo> element. This element has no effect on a response.

Default Value n/a
Required? Optional
Type An array of <QueryParam> elements or an empty array
Parent Element <QueryParam>
Child Elements None

The <QueryParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <!-- Can also be an empty array (<QueryParams/>) -->
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Copy>
</AssignMessage>

Example 1

The following example copies the "my_param" query parameter from the request into a new, custom request object:

<AssignMessage name="copy-queryparams-1">
  <Copy source="request">
    <QueryParams>
      <QueryParam name="my_param"/>
    </QueryParams>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 2

The following example copies all query parameters from the request into a new, custom request object:

<AssignMessage name="copy-queryparams-2">
  <Copy source="request">
    <QueryParams/>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

Example 3

If there are multiple query params with the same name, use the following syntax:

<AssignMessage name="copy-queryparams-3">
  <Copy source="request">
    <QueryParams>
      <QueryParam name="qp1"/>
      <QueryParam name="qp2"/>
      <QueryParam name="qp3.2"/>
    </QueryParams>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

This example copies "qp1", "qp2", and the second value of "qp3". If "qp3" has only one value, then it is not copied.

You can use <QueryParams> only when the following criteria are met:

  • HTTP verb: GET
  • Message type: Request

<ReasonPhrase> (child of <Copy>)

Determines whether the reason phrase should be copied from the source response to the destination response. This element has no effect on a request.

If "true", this policy copies the ReasonPhrase from the response specified by the <Copy> element's source attribute to the response specified by the <AssignTo> element.

Default Value False
Required? Optional
Type Boolean
Parent Element <Copy>
Child Elements None

The <ReasonPhrase> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <ReasonPhrase>[false|true]</ReasonPhrase>
  </Copy>
</AssignMessage>

Example 1

The following example sets <ReasonPhrase> to "true", which causes <Copy> to copy the reason phrase from the default response to a custom response object:

<AssignMessage name="copy-reasonphrase-1">
  <Copy source="response">
    <ReasonPhrase>true</ReasonPhrase>
  </Copy>
  <AssignTo createNew="trie" transport="http" type="response">MyCustomResponse</AssignTo>
</AssignMessage>

You can use <ReasonPhrase> only when the following criteria are met:

  • Message type: Response

<StatusCode> (child of <Copy>)

Determines whether the status code is copied from the source response to the destination response. This element has no effect on a request.

If "true", this policy copies the status code from the response message specified by the <Copy> element's source attribute to the response message specified by the <AssignTo> element.

Default Value False
Required? Optional
Type Boolean
Parent Element <Copy>
Child Elements None

The <StatusCode> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <StatusCode>[false|true]</StatusCode>
  </Copy>
</AssignMessage>

Example 1

The following example sets <StatusCode> to "true", which copies the status code from the default response object to a new, custom response object:

<AssignMessage name="copy-statuscode-1">
  <Copy source="response">
    <StatusCode>true</StatusCode>
  </Copy>
  <AssignTo createNew="true" transport="http" type="response">MyCustomResponse</AssignTo>
</AssignMessage>

You can use <StatusCode> only when the following criteria are met:

  • Message type: Response

A common use of <StatusCode> is to ensure that the proxy response has the same status as the response received from the target when <AssignTo>'s createNew attribute is set to "true".

<Verb> (child of <Copy>)

Determines whether the HTTP verb is copied from the source request to the destination request. This element has no effect on a response.

If "true", copies the verb found in the <Copy> element's source attribute to the request specified in the <AssignTo> element.

Default Value False
Required? Optional
Type Boolean
Parent Element <Copy>
Child Elements None

The <Verb> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <Verb>[false|true]</Verb>
  </Copy>
</AssignMessage>

Example 1

The following example sets <Verb> to "true", which copies the verb from the default request to a new, custom request:

<AssignMessage name="copy-verb-1">
  <Copy source="request">
    <Verb>true</Verb>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

You can use <Verb> only when the following criteria are met:

  • Message type: Request

<Version> (child of <Copy>)

Determines whether the HTTP version is copied from the source request to the destination request. This element has no effect on a response.

If "true", copies the HTTP version found in the <Copy> element's source attribute to the object specified by the <AssignTo> element.

Default Value False
Required? Optional
Type Boolean
Parent Element <Copy>
Child Elements None

The <Version> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Copy source="[request|response]">
    <Version>[false|true]</Version>
  </Copy>
</AssignMessage>

Example 1

The following example sets <Version> to "true" on the request, which copies the version from the default request object to a new, custom request object:

<AssignMessage name="copy-version-1">
  <Copy source="request">
    <Version>true</Version>
  </Copy>
  <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

You can use <Version> only when the following criteria are met:

  • Message type: Request

<DisplayName>

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, more natural-sounding name.

The <DisplayName> element is common to all policies.

Default Value n/a
Required? Optional. If you omit <DisplayName>, the value of the policy's name attribute is used
Type String
Parent Element <PolicyElement>
Child Elements None

The <DisplayName> element uses the following syntax:

Syntax

<PolicyElement>
  <DisplayName>policy_display_name</DisplayName>
  ...
</PolicyElement>

Example

<PolicyElement>
  <DisplayName>My Validation Policy</DisplayName>
</PolicyElement>

The <DisplayName> element has no attributes or child elements.

<IgnoreUnresolvedVariables>

Determines whether processing stops when an unresolved variable is encountered.

Default Value True
Required? Optional
Type Boolean
Parent Element <AssignMessage>
Child Elements None

Set to "true" to ignore unresolved variables and continue processing; otherwise "false". The default value is "true".

Setting <IgnoreUnresolvedVariables> to "true" is different from setting the <AssignMessage>'s continueOnError to "true" in that it is specific to setting and getting values of variables. If you set continueOnError to "true", then Edge ignores all errors, not just errors encountered when using variables.

The <IgnoreUnresolvedVariables> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <IgnoreUnresolvedVariables>[true|false]</IgnoreUnresolvedVariables>
</AssignMessage>

Example 1

The following example sets <IgnoreUnresolvedVariables> to "true":

<AssignMessage name="ignoreunresolvedvariables">
  <Copy source="response">
    ...
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  </Copy>
</AssignMessage>

<Remove>

Removes headers, query parameteters, form parameters, and/or the message payload from a message. The message can be a request or a response. You specify which message <Remove> acts on by using the <AssignTo> element.

Default Value n/a
Required? Optional
Type Complex type
Parent Element <AssignMessage>
Child Elements <FormParams>
<Headers>
<Payload>
<QueryParams>

A common use case for <Remove> is to delete a query parameter that contains sensitive information from the incoming request object, to avoid passing it to the backend server.

The <Remove> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Remove>
    <!-- Can also be an empty array (<FormParams/>) -->
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <!-- Can also be an empty array (<Headers/>) -->
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <Payload>[false|true]</Payload>
    <!-- Can also be an empty array (<QueryParams/>) -->
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Remove>
</AssignMessage>

Example 1

The following example removes the message's body from the response:

<AssignMessage continueOnError="false" enabled="true" name="remove-1">
  <DisplayName>remove-1</DisplayName>
  <Remove>
    <Payload>true</Payload>
  </Remove>
  <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

In the response flow, this policy removes the body of the response, returning only HTTP headers to the client.

Example 2

The following example removes all form parameters and a query parameter from the incoming request:

<AssignMessage continueOnError="false" enabled="true" name="remove-2">
  <Remove>
    <!-- Empty (<FormParams/>) removes all form parameters -->
    <FormParams/>
    <QueryParams>
      <QueryParam name="qp1"/>
    </QueryParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

<FormParams> (child of <Remove>)

Removes the specified form parameters from the request. This element has no effect on a response.

Default Value n/a
Required? Optional
Type Array of <FormParam> elements or an empty array
Parent Element <Remove>
Child Elements <FormParam>

The <FormParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Remove>
    <!-- Can also be an empty array (<FormParams/>) -->
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
  </Remove>
</AssignMessage>

Example 1

The following example removes three form parameters from the request:

<AssignMessage name="remove-formparams-1">
  <Remove>
    <FormParams>
      <FormParam name="form_param_1"/>
      <FormParam name="form_param_2"/>
      <FormParam name="form_param_3"/>
    </FormParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="application/x-www-form-urlencoded"/>
</AssignMessage>

Example 2

The following example removes all form parameters from the request:

<AssignMessage name="remove-formparams-2">
  <Remove>
    <FormParams/>
  </Remove>
  <AssignTo createNew="false" transport="http" type="application/x-www-form-urlencoded"/>
</AssignMessage>

Example 3

If there are multiple form params with the same name, use the following syntax:

<AssignMessage name="remove-formparams-3">
  <Remove>
    <FormParams>
      <FormParam name="f1"/>
      <FormParam name="f2"/>
      <FormParam name="f3.2"/>
    </FormParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="application/x-www-form-urlencoded"/>
</AssignMessage>

This example removes "f1", "f2", and the second value of "f3". If "f3" has only one value, then it is not removed.

You can use <FormParams> only when the following criteria are met:

  • Message type: Request
  • Content-Type: "application/x-www-form-urlencoded"

<Headers> (child of <Remove>)

Removes the specified HTTP headers from the request or response, which is specified by the <AssignTo> element.

Default Value n/a
Required? Optional
Type Array of <Header> elements or an empty array
Parent Element <Remove>
Child Elements <Header>

The <Headers> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Remove>
    <!-- Can also be an empty array (<Headers/>) -->
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
  </Remove>
</AssignMessage>

Example 1

The following example removes the user-agent header from the request:

<AssignMessage name="remove-headers-1">
  <Remove>
    <Headers>
      <Header name="user-agent"/>
    </Headers>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Example 2

The following example removes all headers from the request:

<AssignMessage name="remove-headers-2">
  <Remove>
    <Headers/>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Example 3

If there are multiple headers with the same name, use the following syntax:

<AssignMessage name="remove-headers-3">
  <Remove>
    <Headers>
      <Header name="h1"/>
      <Header name="h2"/>
      <Header name="h3.2"/>
    </Headers>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

This example removes "h1", "h2", and the second value of "h3" from the request. If "h3" has only one value, then it is not removed.

<Payload> (child of <Remove>)

Determines whether <Remove> deletes the payload in the request or response, which is specified by the <AssignTo> element. Set to "true" to clear the payload; otherwise "false". The default value is "false".

Default Value False
Required? Optional
Type Boolean
Parent Element <Remove>
Child Elements None

The <Payload> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Remove>
    <Payload>[false|true]</Payload>
  </Remove>
</AssignMessage>

Example 1

The following example sets <Payload> to "true" so that the request payload is cleared:

<AssignMessage name="remove-payload-1">
  <Remove>
    <Payload>true</Payload>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

<QueryParams> (child of <Remove>)

Removes the specified query parameters from the request. This element has no effect on a response.

Default Value n/a
Required? Optional
Type Array of <QueryParam> elements or an empty array
Parent Element <Remove>
Child Elements <QueryParam>

The <QueryParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Remove>
    <!-- Can also be an empty array (<QueryParams/>) -->
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Remove>
</AssignMessage>

Example 1

The following example removes a single query parameter from the request:

<AssignMessage name="remove-queryparams-1">
  <Remove>
      <QueryParams>
        <QueryParam name="qp1"/>
      </QueryParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Example 2

The following example removes all query parameters from the request:

<AssignMessage name="remove-queryparams-2">
  <Remove>
      <QueryParams/>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Example 3

If there are multiple query params with the same name, use the following syntax:

<AssignMessage name="remove-queryparams-3">
  <Remove>
      <QueryParams>
        <QueryParam name="qp1"/>
        <QueryParam name="qp2"/>
        <QueryParam name="qp3.2"/>
      </QueryParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

This example removes "qp1", "qp2", and the second value of "qp3" from the request. If "qp3" has only one value, then it is not removed.

Example 4

The following example removes the apikey query parameter from the request:

<AssignMessage name="remove-query-param">
  <Remove>
    <QueryParams>
      <QueryParam name="apikey"/>
    </QueryParams>
  </Remove>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

You can use <QueryParams> only when the following criteria are met:

  • HTTP verb: GET
  • Message type: Request

<Set>

Sets information in the request or response message, which is specified by the <AssignTo> element. <Set> overwrites headers or parameters that already exist in the original message. To create a new header or parameter, use the <Add> element instead.

Default Value n/a
Required? Optional
Type Complex type
Parent Element <AssignMessage>
Child Elements <FormParams>
<Headers>
<Payload>
<Path>
<QueryParams>
<ReasonPhrase>
<StatusCode>
<Verb>
<Version>

The <Set> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
    <Path>path</Path>
    <Payload contentType="content_type" variablePrefix="prefix"
        variableSuffix="suffix">new_payload</Payload>
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
    <ReasonPhrase>reason_for_error or {variable}</ReasonPhrase>
    <StatusCode>HTTP_status_code or {variable}</StatusCode>
    <Verb>[GET|POST|PUT|PATCH|DELETE|{variable}]</Verb>
    <Version>[1.0|1.1|{variable}]</Verb>
  </Set>
</AssignMessage>

Example 1

The following example shows the <Set> element:

<AssignMessage continueOnError="false" enabled="true" name="set-1">
  <Set>
    <FormParams>
      <FormParam name="myparam">{request.header.myparam}</FormParam>
    </FormParams>
    <Headers>
        <Header name="user-agent">{request.header.user-agent}</Header>
    </Headers>
    <QueryParams>
      <QueryParam name="name">{request.header.name}</QueryParam>
      <QueryParam name="address">{request.header.address}</QueryParam>
    </QueryParams>
    <!-- <Verb>GET</Verb> -->
    <Payload contentType="text/plain">42</Payload>
    <Path/>
    <ReasonPhrase>Bad request</ReasonPhrase>
    <StatusCode>400</StatusCode>
    <Verb>POST</Verb>
    <Verb>{my_variable}</Verb>
    <Version>1.1</Version>
  </Set>
  <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

<FormParams> (child of <Set>)

Overwrites existing form parameters on a request and replaces them with the new values that you specify with this element. This element has no effect on a response.

Default Value n/a
Required? Optional
Type Array of <FormParam> elements
Parent Element <Set>
Child Elements <FormParam>

The <FormParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <FormParams>
      <FormParam name="formparam_name">formparam_value</FormParam>
      ...
    </FormParams>
  </Set>
</AssignMessage>

Example 1

The following example sets a form parameter called "myparam" to the value of the request.header.myparam variable in a new, custom request:

<AssignMessage name="set-formparams-1">
  <Set>
    <FormParams>
      <FormParam name="myparam">{request.header.myparam}</FormParam>
    </FormParams>
  </Set>
    <AssignTo createNew="true" transport="http" type="request">MyCustomRequest</AssignTo>
</AssignMessage>

You can use <FormParams> only when the following criteria are met:

  • HTTP verb: POST
  • Message type: Request

If you define empty form parameters in your policy (<Add><FormParams/></Add>), the policy does not add any form parameters. This is the same as omitting the <FormParams>.

<Set> changes the Content-Type of the message to "application/x-www-form-urlencoded" before sending it to the target endpoint.

<Headers> (child of <Set>)

Overwrites existing HTTP headers in the request or response, which is specified by the <AssignTo> element.

Default Value n/a
Required? Optional
Type Array of <Header> elements
Parent Element <Set>
Child Elements <Header>

The <Headers> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <Headers>
      <Header name="header_name">header_value</Header>
      ...
    </Headers>
  </Set>
</AssignMessage>

Example 1

The following example sets the user-agent header to the value of the request.header.user-agent variable:

<AssignMessage name="set-headers-1">
  <Set>
    <Headers>
      <Header name="user-agent">{request.header.user-agent}</Header>
    </Headers>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

If you define empty headers in your policy (<Add><Headers/></Add>), the policy does not add any headers. This is the same as omitting <Headers>.

<Path> (child of <Set>)

<Payload> (child of <Set>)

Defines the message body for a request or response, which is specified by the <AssignTo> element. The payload can be any valid content type, such as plain text, JSON, or XML.

Default Value empty string
Required? Optional
Type String
Parent Element <Set>
Child Elements None

The <Payload> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <Payload contentType="content_type" variablePrefix="prefix"
        variableSuffix="suffix">new_payload</Payload>
  </Set>
</AssignMessage>

Example 1

The following example sets a plain text payload:

<AssignMessage name="set-payload-1">
  <Set>
    <Payload contentType="text/plain">42</Payload>
  </Set>
</AssignMessage>

Example 2

The following example sets a JSON payload:

<AssignMessage name="set-payload-2">
  <Set>
    <Payload contentType="application/json">
      {"name":"foo", "type":"bar"}
    </Payload>
  </Set>
</AssignMessage>

Example 3

The following example inserts variable values into the payload by wrapping variable names in curly braces:

<AssignMessage name="set-payload-3">
  <Set>
    <Payload contentType="application/json">
      {"name":"foo", "type":"{variable_name}"}
    </Payload>
  </Set>
</AssignMessage>

In older versions of Apigee Edge—for example, prior to cloud release 16.08.17—you could not use curly braces to denote variable references within JSON payloads. In those releases, you needed to use the variablePrefix and variableSuffix attributes to specify delimiter characters, and use those to wrap variable names, like so:

<AssignMessage name="set-payload-3b">
  <Set>
    <Payload contentType="application/json" variablePrefix="@" variableSuffix="#">
      {"name":"foo", "type":"@variable_name#"}
    </Payload>
  </Set>
</AssignMessage>

This older syntax still works.

Example 4

The content of <Payload> is treated as a message template. This means that the Assign Message policy replaces variables wrapped in curly braces with the value of the referenced variables at runtime.

The following example uses the curly braces syntax to set part of the payload to a variable value:

<AssignMessage name="set-payload-4">
  <Set>
    <Payload contentType="text/xml">
      <root>
        <e1>sunday</e1>
        <e2>funday</e2>
        <e3>{var1}</e3>
      </root>
    </Payload>
  </Set>
</AssignMessage>

The following table describes the attributes of <Payload>:

Attribute Description Presence Type
contentType

If specified, the value of contentType is assigned to the Content-Type HTTP header.

Optional String
variablePrefix Optionally specifies the leading delimiter on a flow variable. Defaults to "{". For more information, see Flow variables reference. Optional Char
variableSuffix Optionally specifies the trailing delimiter on a flow variable. Defaults to "}". For more information, see Flow variables reference. Optional Char

<QueryParams> (child of <Set>)

Overwrites existing query parameters in the request with new values. This element has no effect on a response.

Default Value n/a
Required? Optional
Type Array of <QueryParam> elements
Parent Element <Set>
Child Elements <QueryParam>

The <QueryParams> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <QueryParams>
      <QueryParam name="queryparam_name">queryparam_value</QueryParam>
      ...
    </QueryParams>
  </Set>
</AssignMessage>

Example 1

The following example sets the "address" query parameter to the value of the request.header.address variable:

<AssignMessage continueOnError="false" enabled="true" name="set-queryparams-1">
  <Set>
    <QueryParams>
      <QueryParam name="address">{request.header.address}</QueryParam>
    </QueryParams>
  </Set>
</AssignMessage>

You can use <QueryParams> only when the following criteria are met:

  • HTTP verb: GET
  • Message type: Request

If you define empty query parameters in your policy (<Set><QueryParams/></Set>), the policy does not set any query parameters. This is the same as omitting <QueryParams>.

<ReasonPhrase> (child of <Set>)

Sets the reason phrase on the response. This is normally done for debugging in combination with <StatusCode>. This element has no effect on a request.

Default Value n/a
Required? Optional
Type String
Parent Element <Set>
Child Elements None

The <ReasonPhrase> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <ReasonPhrase>reason_for_error or {variable}</ReasonPhrase>
  </Set>
</AssignMessage>

Example 1

The following example defines a simple reason phrase:

<AssignMessage name="set-reasonphrase-1">
  <Set>
    <ReasonPhrase>Bad medicine</ReasonPhrase>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

Example 2

The content of <ReasonPhrase> is treated as a message template. This means a variable name wrapped in curly braces will be replaced at runtime with the value of the referenced variable, as the following example shows:

<AssignMessage name="set-reasonphrase-2">
  <Set>
    <ReasonPhrase>{calloutresponse.reason.phrase}</ReasonPhrase>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

You can use <ReasonPhrase> only when the following criteria are met:

  • Message type: Response

<StatusCode> (child of <Set>)

Sets the status code on the response. This element has no effect on a request.

Default Value '200' (when <AssignTo>'s createNew attribute is set to 'true')
Required? Optional
Type String or variable
Parent Element <Set>
Child Elements None

The <StatusCode> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <StatusCode>HTTP_status_code or {variable}</StatusCode>
  </Set>
</AssignMessage>

Example 1

The following example sets a simple status code:

<AssignMessage name="set-statuscode-1">
  <Set>
    <StatusCode>404</StatusCode>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

Example 2

The content of <StatusCode> is treated as a message template. This means a variable name wrapped in curly braces will be replaced at runtime with the value of the referenced variable, as the following example shows:

<AssignMessage name="set-statuscode-2">
  <Set>
    <StatusCode>{calloutresponse.status.code}</StatusCode>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

You can use <StatusCode> only when the following criteria are met:

  • Message type: Response

<Verb> (child of <Set>)

Sets the HTTP verb on the request. This element has no effect on a response.

Default Value n/a
Required? Optional
Type String or variable
Parent Element <Set>
Child Elements None

The <Verb> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <Verb>[GET|POST|PUT|PATCH|DELETE|{variable}]</Verb>
  </Set>
</AssignMessage>

Example 1

The following example sets a simple verb on the request:

<AssignMessage name="set-verb-1">
  <Set>
    <Verb>POST</Verb>
  </Set>
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

Example 2

The content of <Verb> is treated as a message template. This means a variable name wrapped in curly braces will be replaced at runtime with the value of the referenced variable.

The following example uses a variable to populate a verb:

<AssignMessage name="set-verb-2">
  <Set>
    <Verb>{my_variable}</Verb>
  </Set>
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

You can use <Verb> only when the following criteria are met:

  • Message type: Request

<Version> (child of <Set>)

Sets the HTTP version on a request. This element has no effect on a response.

Default Value n/a
Required? Optional
Type String or variable
Parent Element <Set>
Child Elements None

The <Version> element uses the following syntax:

Syntax

<AssignMessage
    continueOnError="[false|true]"
    enabled="[true|false]"
    name="policy_name" >
  <Set>
    <Version>[1.0|1.1|{variable}]</Verb>
  </Set>
</AssignMessage>

Example 1

The following example sets the version number to "1.1":

<AssignMessage name="set-version-1">
  <Set>
    <Version>1.1</Version>
  </Set>
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

Example 2

The following uses a variable in curly braces to set the version number:

<AssignMessage name="set-version-2">
  <Set>
    <Version>{my_version}</Version>
  </Set>
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

The content of <Version> is treated as a message template. This means a variable name wrapped in curly braces will be replaced at runtime with the value of the referenced variable.

You can use <Version> only when the following criteria are met:

  • Message type: Request

Create custom request messages

You can use Assign Message to create a custom request message. After you create a custom request, you can use it in the following ways:

  • Access its variables in other policies
  • Pass it to an external service

To create a custom request message, use the <AssignTo> element in your Assign Message policy. Set createNew to "true" and specify the name of the new message in the body of the element, as the following example shows:

<AssignMessage name="assignto-2">
  <AssignTo createNew="true" transport="http" type="request"/>
</AssignMessage>

By default, Edge does nothing with the custom request message. After creating it, Edge will continue through the flow with the original request. To use the custom request, add a policy such as the ServiceCallout policy to your proxy that can pass the custom request to an external service.

The following examples create custom request messages:

Example 1

The following example creates a custom request object with Assign Message:

<AssignMessage name="AssignMessage-3">
  <AssignTo createNew="true" type="request">MyCustomRequest</AssignTo>
  <Copy>
    <Headers>
     <Header name="user-agent"/>
    </Headers>
  </Copy>
  <Set>
    <QueryParams>
      <QueryParam name="address">{request.queryparam.addy}</QueryParam>
    </QueryParams>
    <Verb>GET</Verb>
  </Set>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</AssignMessage>

This example:

  • Creates a new request message object called "MyCustomRequest".
  • On MyCustomRequest, this policy:
    • Copies the value of the user-agent HTTP header from the incoming request to the new message. Because <Copy> uses an absolute reference to the user-agent flow variable, there is no need to specify the source attribute to <Copy>.
    • Sets the address query parameter on the custom message to the value of the incoming request's addy query parameter.
    • Sets the HTTP verb to GET.
  • Sets <IgnoreUnresolvedVariables> to "false". When <IgnoreUnresolvedVariables> is "false", if one of the variables the policy tries to add does not exist, Edge will stop processing in the API flow.

Example 2

Here's another example demonstrating how to create a custom request object with Assign Message:

<AssignMessage name="AssignMessage-2">
  <AssignTo createNew="true" type="request">partner.request</AssignTo>
  <Set>
    <Verb>POST</Verb>
    <Payload contentType="text/xml">
      <request><operation>105</operation></request>
    </Payload>
  </Set>
</AssignMessage>

This example creates a new custom request called "partner.request". It then sets the <Verb> and <Payload> on the new request.

You can access a custom request message in another Assign Message policy that occurs later in the flow. The following example gets the value of the custom request message's user-agent header:

<AssignMessage name="custom-request-1-access">
  <DisplayName>custom-request-1-access</DisplayName>
  <AssignTo createNew="false" type="request"></AssignTo>
  <Set>
    <Headers>
      <Header name="user-agentCopyCustomRequest">{MyCustomRequest.header.user-agent}</Header>
    </Headers>
  </Set>
</AssignMessage>

Videos

Watch the following videos to learn more about the Assign Message policy.

Video Description
Why Assign Message Policy? Learn about the benefits of using Assign Message policy to modify the API request or response without modifying the backend code.
Copy API elements using Assign Message policy Copy elements from an API request or response and construct a new request or response object using the Assign Message policy.
Remove API elements using Assign Message policy Remove API elements and modify the API before it reaches the target backend using the Assign Message policy.
Add and set API elements using Assign Message policy Change API request or response by adding query parameters, headers, form parameters, or payloads using the Assign Message policy.
Create custom variables using Assign Message policy Set custom flow variables using Assign Message policy and leverage the variables in other policies in the API proxy.
Create new request or response objects using Assign Message policy Create new API request or response objects using the Assign Message policy at API runtime.
Create a mock API using Assign Message policy Create a simple mock REST API by adding the Assign Message policy in the response flow.
Set or modify the payload using Assign Message policy Convert REST request to SOAP request by setting SOAP Payload using the Assign Message policy at API runtime.

Error codes

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause Fix
steps.assignmessage.SetVariableFailed 500 The policy was not able to set a variable. See the fault string for the name of the unresolved variable.
steps.assignmessage.VariableOfNonMsgType 500

This error occurs if the source attribute in the <Copy> element is set to a variable which is not of type message.

Message type variables represent entire HTTP requests and responses. The built-in Edge flow variables request, response, and message are of type message. To learn more about message variables, see the Variables reference.

build
steps.assignmessage.UnresolvedVariable 500

This error occurs if a variable specified in the Assign Message policy is either:

  • out of scope (not available in the specific flow where the policy is being executed)
  • or
  • can't be resolved (is not defined)
build

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause Fix
InvalidIndex If the index specified in the <Copy> and/or <Remove> elements of the Assign Message policy is 0 or a negative number, then deployment of the API Proxy fails. build
InvalidVariableName If the child element <Name> is empty or not specified in the <AssignVariable> element, then the deployment of the API proxy fails because there is no valid variable name to which to assign a value. A valid variable name is required. build
InvalidPayload A payload specified in the policy is invalid.

Fault variables

These variables are set when this policy triggers an error at runtime. For more information, see What you need to know about policy errors.

Variables Where Example
fault.name="fault_name" fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. fault.name Matches "UnresolvedVariable"
assignmessage.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. assignmessage.AM-SetResponse.failed = true

Example error response

{  
   "fault":{  
      "detail":{  
         "errorcode":"steps.assignmessage.VariableOfNonMsgType"
      },
      "faultstring":"AssignMessage[AM-SetResponse]: value of variable is not of type Message"
   }
}

Example fault rule

<faultrule name="VariableOfNonMsgType"></faultrule><FaultRule name="Assign Message Faults">
    <Step>
        <Name>AM-CustomNonMessageTypeErrorResponse</Name>
        <Condition>(fault.name Matches "VariableOfNonMsgType") </Condition>
    </Step>
    <Step>
        <Name>AM-CustomSetVariableErrorResponse</Name>
        <Condition>(fault.name = "SetVariableFailed")</Condition>
    </Step>
    <Condition>(assignmessage.failed = true) </Condition>
</FaultRule>

Schemas

Each policy type is defined by an XML schema (.xsd). For reference, policy schemas are available on GitHub.

Related topics

Working samples of the AssignMessage policy are available in the API Platform samples.

For a more advanced example of how to override the target.url from the ProxyEndpoint, see this Apigee Community article.

To see a "set path" in action in a ServiceCallout policy, check out this Learn by doing example in the Apigee GitHub samples. Just clone the repository and follow the instructions in that topic. The example uses Assign Message to set a request path, then uses a Service Callout policy to make the request to an external service.