DataPower API Gateway
only

Extract

Use the Extract policy to extract and transform data from fields in the API context.

Before you begin

Table 1. Gateways that support this policy and the corresponding policy versions
Gateway Policy version
DataPower® API Gateway 2.0.0

This topic describes how to configure the policy in the assembly editor. For details about how to configure the policy in your OpenAPI source, see extract.

About this task

The Extract policy specifies the data source that contains the content to transform, the fields that contain the content, and expressions that define how to transform the content. You use a subset of JSONata notation to specify the fields to extract and transform. For more information, see Constructing JSONata expressions to extract and transform data.

The input to the Extract policy must be parsed data. One way to produce parsed data is to add a Parse policy before the Extract policy in your assembly.

Procedure

  1. In the navigation pane, click Develop icon in the navigation pane Develop, then select the APIs tab.
    The Develop page opens.
  2. Click the title of the API definition that you want to work with.
  3. Select the Gateway tab, then click Policies in the navigation pane.
    For more information about working with the assembly editor for an API, see The assembly editor.
  4. Find the Extract policy in the palette, and drag the policy onto your canvas.
  5. Specify the following properties.
    Table 2. Extract policy properties
    Property label Required Description Data type
    Title Yes The title of the policy.

    The default value is extract.

    string
    Description No A description of the policy. string
    Root Yes The data source that contains the content to transform.

    The default value is message.body.

    string
    Capture Yes The path expression that identifies the field.

    The default setting is $, which indicates the entire input.

    string
    Transform Yes The expression that defines how to transform the content. string
  6. Specify a version for the policy by clicking the Source icon OpenAPI Source icon, and completing the version section of the policy YAML. For example:
    execute:
      - extract:
          version: 2.0.0
          title: extract
    ...
    You must specify a version for the policy that is compatible with the gateway that you are using. When the API is published, if the version is incompatible with the gateway, a validation error is thrown that specifies the available versions.
  7. Click Save.

Example

Transform the contents of the account field to include only the last 4 characters.
- extract:
    version: 2.0.0
    title: extract
    root: message.body
    extracts:
      - capture: $.members.policy.**.account
        transform: $substring($,-4)
    description: Include only the last 4 characters of the account field.