Skip to content

gravitee-io/gravitee-policy-assign-attributes

Repository files navigation

Assign attributes

Gravitee.io License Releases CircleCI

Overview

You can use the policy-assign-attributes policy to set variables such as request attributes, message attributes, and other execution context attributes.

NOTE: When you use this policy on message request or message response phases, attributes are stored in the message attribute list instead of the context attribute list.

This policy is useful to keep initial request data after policies such as Transform headers or Transform query parameters, and reuse these values in downstream policies like Dynamic routing.

Phases

The policy-assign-attributes policy can be applied to the following API types and flow phases.

Compatible API types

  • PROXY
  • MESSAGE
  • NATIVE KAFKA
  • MCP PROXY
  • LLM PROXY
  • A2A PROXY

Supported flow phases:

  • Request
  • Response
  • Publish
  • Subscribe
  • Interact

Compatibility matrix

Strikethrough text indicates that a version is deprecated.

Plugin version APIM
3.x 4.8.x to latest
2.x 4.0.x to 4.7.x
1.x 3.x

Configuration options

Name
json name
Type
constraint
Mandatory Description
Assign context attributes
attributes
array
See "Assign context attributes" section.

Assign context attributes (Array)

Name
json name
Type
constraint
Mandatory Description
Name
name
string Name of the attribute.
Value
value
string Value of the attribute (Support EL).

Examples

Proxy API on Request phase

{
  "api": {
    "definitionVersion": "V4",
    "type": "PROXY",
    "name": "Assign attributes example API",
    "flows": [
      {
        "name": "Common Flow",
        "enabled": true,
        "selectors": [
          {
            "type": "HTTP",
            "path": "/",
            "pathOperator": "STARTS_WITH"
          }
        ],
        "request": [
          {
            "name": "Assign attributes",
            "enabled": true,
            "policy": "policy-assign-attributes",
            "configuration":
              {
                  "scope": "REQUEST_CONTENT",
                  "attributes": [
                      {
                          "name": "test-request-content",
                          "value": "{#jsonPath(#request.content, '$.registrationForm.firstName')}"
                      },
                      {
                          "name": "test-request-content1",
                          "value": "{#jsonPath(#request.content, '$.registrationForm.birthDate')}"
                      },
                      {
                          "name": "test-request-content2",
                          "value": "{#jsonPath(#request.content, '$.registrationForm.username')}"
                      }
                  ]
              }
          }
        ]
      }
    ]
  }
}

Proxy API on Response phase

{
  "api": {
    "definitionVersion": "V4",
    "type": "PROXY",
    "name": "Assign attributes example API",
    "flows": [
      {
        "name": "Common Flow",
        "enabled": true,
        "selectors": [
          {
            "type": "HTTP",
            "path": "/",
            "pathOperator": "STARTS_WITH"
          }
        ],
        "response": [
          {
            "name": "Assign attributes",
            "enabled": true,
            "policy": "policy-assign-attributes",
            "configuration":
              {
                  "scope": "RESPONSE_CONTENT",
                  "attributes": [
                      {
                          "name": "test-response-content",
                          "value": "{#jsonPath(#response.content, '$.responseForm.firstName')}"
                      },
                      {
                          "name": "test-response-content1",
                          "value": "{#jsonPath(#response.content, '$.responseForm.birthDate')}"
                      },
                      {
                          "name": "test-response-content2",
                          "value": "{#jsonPath(#response.content, '$.responseForm.username')}"
                      }
                  ]
              }
          }
        ]
      }
    ]
  }
}

Message API CRD on Subscribe phase

apiVersion: "gravitee.io/v1alpha1"
kind: "ApiV4Definition"
metadata:
    name: "policy-assign-attributes-message-api-crd"
spec:
    name: "Assign attributes example"
    type: "MESSAGE"
    flows:
      - name: "Common Flow"
        enabled: true
        selectors:
            matchRequired: false
            mode: "DEFAULT"
        subscribe:
          - name: "Assign attributes"
            enabled: true
            policy: "policy-assign-attributes"
            configuration:
              attributes:
                  - name: test-message-response-attr1
                    value: '{#message.content}'

Changelog

3.2.0 (2026-02-18)

Features

3.1.0 (2025-12-11)

Features
  • enable for LLM & MCP Proxy API (cc71b88)

3.1.0-alpha.1 (2025-11-12)

Features
  • enable for LLM & MCP Proxy API (731bf8f)

3.0.2 (2025-09-01)

Bug Fixes
  • use this policy on request/response phases (c4e4e35)

3.0.1 (2025-07-02)

Bug Fixes
  • changed flatMapMaybe to concatMapMaybe (31e7d81)

3.0.0 (2025-06-17)

chore
  • make policy compatible with apim 4.8.0 (424cf3e)
Features
  • enable assign attribute policy for native apis (619b191)
BREAKING CHANGES
  • require APIM 4.8.0+ to work

2.0.3 (2024-09-13)

Bug Fixes
  • json-schema - remove json forced language (2eac825)

2.0.2 (2024-09-11)

Bug Fixes
  • json-schema - add code editor for attribute values (9fa4a86)

2.0.1 (2023-07-20)

Bug Fixes
  • update policy description (723e2ca)

2.0.0 (2023-07-18)

Bug Fixes
  • add missing breaking change and update compatibility matrix in README (791eac8)
  • bump gravitee-parent to fix release to nexus (e4d0957)
  • use new execution engine (21ea3f7)
chore
  • deps: update gravitee-parent (bd51e10)
Features
  • add message level support to policy (676fc6f)
  • clean and validate json schema for v4 (f915aca)
BREAKING CHANGES
  • deps: require Java17
  • This implementation is using the dependencies introduced by Gravitee V4.0

2.0.0-alpha.4 (2023-06-29)

Bug Fixes
  • use new execution engine (21ea3f7)

2.0.0-alpha.3 (2023-06-27)

Features
  • clean and validate json schema for v4 (f915aca)

2.0.0-alpha.2 (2023-06-23)

Bug Fixes
  • bump gravitee-parent to fix release to nexus (e4d0957)

2.0.0-alpha.1 (2023-06-21)

Bug Fixes
  • add missing breaking change and update compatibility matrix in README (791eac8)
BREAKING CHANGES
  • This implementation is using the dependencies introduced by Gravitee V4.0

1.6.0-alpha.1 (2023-06-20)

Features
  • add message level support to policy (676fc6f)

1.5.1 (2023-01-23)

Bug Fixes
  • properly set response attribute in the execution context (f8d4de4)

About

Gravitee Policy - Assign attributes

Topics

Resources

License

Contributing

Stars

0 stars

Watchers

24 watching

Forks

Packages

 
 
 

Contributors

Languages