You want to apply an API Manager policy to an existing API via the API.
curl 'https://anypoint.mulesoft.com/apimanager/api/v1/organizations/< org ID from step 2>/environments/<env ID from step 3>/apis/<API ID from step 4>/policies' -X POST -H 'Accept: application/json, text/plain, */*' -H 'X-ANYPNT-ORG-ID: <org ID from steo 2>' -H 'X-ANYPNT-ENV-ID: <env ID from step 3>' -H 'Content-Type: application/json;charset=utf-8' --data-raw
'{
"configurationData": {
"ipExpression": "#[attributes.headers['x-forwarded-for']]",
"ips": [
"1.1.1.1"
]
},
"apiVersionId": <API ID from step 4>,
"pointcutData": null,
"policyTemplateId": null,
"groupId": "68ef9520-24e9-4cf2-b2f5-620025690913",
"assetId": "ip-allowlist",
"assetVersion": "1.1.1"
}'
6. If you need the exact parameters for each policy, you can first add the policy via the UI and then perform a GET on the same endpoint. For example, I have added header injection and OAuth 2.0 access token enforcement using Mule OAuth provider and then ran a GET call against the above URL:curl 'https://anypoint.mulesoft.com/apimanager/api/v1/organizations/<org ID from step 2>/environments/<env ID from step 3>/apis/<API ID from step 4>/policies' -X GET -H 'Accept: application/json, text/plain, */*' -H 'Authorization: Bearer <bearer token from step 1>' -H 'X-ANYPNT-ENV-ID: <env ID from step 3> -H 'Content-Type: application/json;charset=utf-8'
{
"policies": [
{
"policyTemplateId": "<hidden>",
"order": 1,
"pointcutData": null,
"type": "system",
"policyId": <hidden>,
"configuration": {
"scopeValidationCriteria": "AND",
"tokenUrl": "https://www.google.com",
"secureTrustStore": false,
"exposeHeaders": false,
"skipClientIdValidation": true,
"authenticationTimeout": 10000
},
"template": {
"groupId": "68ef9520-24e9-4cf2-b2f5-620025690913",
"assetId": "external-oauth2-access-token-enforcement",
"assetVersion": "1.5.1"
},
"version": <hidden>
},
{
"policyTemplateId": "<hidden>",
"order": 2,
"pointcutData": null,
"implementationAsset": {
"assetId": "header-injection-mule",
"groupId": "68ef9520-24e9-4cf2-b2f5-620025690913",
"version": "1.3.0",
"minRuntimeVersion": "4.1.0"
},
"type": "system",
"policyId": <hidden>,
"configuration": {
"inboundHeaders": [],
"outboundHeaders": []
},
"template": {
"groupId": "68ef9520-24e9-4cf2-b2f5-620025690913",
"assetId": "header-injection",
"assetVersion": "1.3.1"
},
"version": <hidden>
}
]
}
001115318

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.