This guide provides instructions for creating, configuring, and deploying a custom Mule 4 policy that sends incoming request payloads and headers to an external API endpoint (e.g., a webhook) when a request is received.
- Refer to the top-level
README.mdfor prerequisites (Java 17, Anypoint Studio 7.21.0, MuleSoft account) andsettings.xmlsetup.
Reference: MuleSoft Custom Policy Documentation
A sample custom policy is available in this directory (custom-api-call-policy).
-
Obtain Organization ID:
- Go to https://anypoint.mulesoft.com/accounts/businessGroups.
- Select your business group and note the Business Group ID.
-
Update the groupId of the policy:
- Open treblle-policy/pom.xml
- Change {Use Business Group ID here}
- Update Credentials
In order to add the custom policy to the organization, we have to build and push the policy to the MuleSoft. Hence we need to update the credentials.
-
Navigate to samples/.m2/settings.xml
-
Update the credentials
<username>{MuleSoft Username}</username> <password>{MuleSoft Password}</password>
- Push the API Policy to the Mule Exchange
-
Build and push the API policy (Execute this inside the treblle-policy/ folder)
mvn -s ../samples/.m2/settings.xml clean package mvn -s ../samples/.m2/settings.xml clean deploy
- Verify Policy:
- Visit https://anypoint.mulesoft.com/exchange.
- Search for treblle policy to confirm the policy is available.
- Apply Policy in API Manager:
- In Anypoint Platform, navigate to API Manager.
- Select your API (e.g.,
hello-world). - Go to Policies and click Apply New Policy.
- Choose treblle-policy from the list.
- Configure the policy with the following values:
- API Key:
API Key - SDK Token:
SDK token - Mask Keywords:
Comma-separated list of masking keywords
- API Key:
- Save and Apply:
- Save the policy configuration and apply it to the API.
- Invoke the API:
- Invoke the API and check Treblle Dashboard.