You can use the assign-content policy to change or transform the content of the request/response body or message.
This policy is compatible with the Freemarker template engine, which allows you to apply complex transformations, such as transforming from XML to JSON and vice versa.
By default, you can access multiple objects from the template context — request and response bodies, dictionaries, context attributes and more.
| Plugin version | APIM version | Java version |
|---|---|---|
Up to 1.6.x |
Up to 3.9.x |
8 |
1.7.x |
3.10.x to 3.20.x |
11 |
2.x |
4.0.x to 4.8.x |
17 |
3.x |
4.9.x to latest |
21 |
The Java version column is the bytecode level of the latest release of each line, which sets the minimum runtime able to load the artifact.
| Property | Required | Description | Type | Default |
|---|---|---|---|---|
scope |
X |
The execution scope of the policy. |
scope |
REQUEST |
body |
X |
The data to push as request or response body content. |
string |
- |
"policy-assign-content": {
"scope":"REQUEST",
"body":"Put your content here"
}{
"example": "${context.dictionaries['my-dictionary']['my-value']}",
"application": "${context.attributes['application']}"
}|
Tip
|
You can find more information about default attributes in the Expression Language documentation in the API Publisher Guide. |
Input:
<#assign body = request.content?eval >
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:GetQuote>
${body.symbol}
</web:GetQuote>
</soapenv:Body>
</soapenv:Envelope>Expected output:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:GetQuote>
EUR
</web:GetQuote>
</soapenv:Body>
</soapenv:Envelope>