Set context variable

The Set context variable sets one or more custom context variables during API execution under the specified conditions.

In IBM API Studio, this policy is identified by the kind SetContextVariable.

Example of a Set context variable policy:

kind: SetContextVariable
apiVersion: api.ibm.com\v1
metadata:
  name: setcontextvariable
  version: 1
  spec:
    condition: |
      (${request.httpMethod} equals POST) or 
      (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
    # other operators include Equals, Equals ignore case, Not equals, Not equals ignore case, Contains, Not Contains, Exists, Not Exists, IP Range, Greater Than, Lesser Than
    variable:
      - name: customerName
        value: ${request.headers.h1}
      - name: customerName
        value: ${request.payload.xpath[/s:sdd/sd]}
    namespaces:
      - prefix: support
        URI: http://test.com

For the Set context variable policy, configure these specifications:

Property Description
spec
  • Conditions are used to specify when the policy is run. You can add multiple conditions with logical operators. Provide the condition in the format: {set} operator {value} condition {set} operator {value}

    • Use one of these conditions.
    • Transform the requests that comply with all the configured conditions in the code view by using and.
    • Transform the requests that comply with any one configured condition in the code view by using or.
    • You can use the following operators:
    • Equals
    • Equals ignore case
    • Not equals
    • Not equals ignore case
    • Contains
    • Not Contains
    • Exists
    • Not Exists
    • IP Range
    • Greater Than
    • Lesser Than
  • variable. Extracts and store values from the request, which can be used later in the policy execution.
    • Configure these fields:
    • name. Name that is assigned to the variable.
    • value. Expression used to extract the values.
  • namespaces. Defines the namespaces that are used in the queries.
    • Configure these fields:
    • prefix. A short identifier for the namespace.
    • URI. The full namespace URI that the prefix maps to.