Treblle Policy for MuleSoft
This is Treblle’s official MuleSoft policy that enables organizations to discover and get full visibility into all their APIs.
The policy also enables features like payload masking and captures detailed API-specific metadata to give you the best Treblle experience.
Prerequisites
Before you begin, make sure you have:
- MuleSoft API Gateway 4+
- Java 17 or higher
- Anypoint Studio 7.21.0 or later
- An active MuleSoft account with API Manager access
- Maven 3.8+ configured with proper
settings.xml - A Treblle account with API key and SDK token
Creating and Deploying the Custom Policy
This guide will walk you through creating, configuring, and deploying a custom Mule 4 policy that sends incoming request payloads and headers to Treblle when a request is received.
Obtaining Organization ID
- Navigate to Anypoint Platform Business Groups
- Select your business group
- Note the Business Group ID from the URL or page details. You’ll need this for the next step.
Note
The Business Group ID is a unique identifier that looks like: 68ef933a-6a4e-4d9d-8262-9c2a93c11111
Updating Policy Configuration
-
Clone the Treblle MuleSoft repository:
git clone https://github.com/Treblle/treblle-mulesoft.git cd treblle-mulesoft -
Open
treblle-policy/pom.xmland update thegroupIdwith your Business Group ID:<groupId>{BUSINESS_GROUP_ID}</groupId>
Configuring Maven Settings
-
Navigate to the
samples/.m2/settings.xmlfile -
Update your MuleSoft credentials:
<username>{YOUR_MULESOFT_USERNAME}</username> <password>{YOUR_MULESOFT_PASSWORD}</password>
Caution
Ensure your MuleSoft account has sufficient permissions to deploy to Exchange. You may need the Exchange Contributor or Exchange Administrator role.
Building and Deploying the Policy
-
Navigate to the
treblle-policydirectory:cd treblle-policy -
Build the policy:
mvn -s ../samples/.m2/settings.xml clean package -
Deploy to MuleSoft Exchange:
mvn -s ../samples/.m2/settings.xml clean deploy
Tip
If you encounter permission errors during deployment, verify that your MuleSoft account has the necessary API Manager and Exchange permissions.
Verifying Policy Installation
- Visit Anypoint Exchange
- Search for “treblle policy”
- Confirm the policy is available in your organization
The policy should appear with version 1.0.0 and display as a Custom Policy.
Applying the Treblle Policy to Your API
Configuring API Manager
- Log in to Anypoint Platform
- Navigate to API Manager
- Select your API (e.g.,
hello-world) - Go to the Policies tab
- Click Apply New Policy
Note
Ensure your API is already deployed and running in CloudHub or Runtime Manager before applying the policy.
Configuring Treblle Policy
- Choose treblle-policy from the list of available policies
- Configure the policy with your Treblle credentials:
- API Key: Enter your Treblle API key
- SDK Token: Enter your Treblle SDK token
Applying and Testing
- Save the policy configuration
- Apply the policy to your API
- Invoke your API endpoint with a test request
- Check your Treblle Dashboard to see the API traffic
The request should appear in Treblle within a few seconds, including headers, payload, and response data.
Using Automated Policy for Multiple APIs
If you want to group all your APIs under a single Treblle policy configuration, you can use the Automated Policy feature. This approach means that all your APIs will share the same data masking settings and appear as one unified API on the Treblle platform, rather than adding the Treblle policy to each API manually.
Note
Recommended to be configured while on a call with the Treblle team to ensure it’s set up correctly and optimized for your use case. Please reach out to your Treblle point of contact before starting, so they can guide you through the setup and help address any specifics in real time.
Setting up Automated Policy
1. Navigate to Automated Policies
- Go to API Manager in your Anypoint Platform
- On the left sidebar, locate and click on Automated Policies
2. Configure the Treblle Policy
-
Click Add to create a new automated policy
-
Select the
treblle-policyfrom the available policies -
Configure the following required fields:
- API Key: Enter your Treblle API Key
- SDK Token: Enter your Treblle SDK Token
- Mask Keywords: Add any sensitive data fields you want to mask (e.g., email,id)
3. Advanced Configuration Options
-
Click on Advanced options to configure policy version and application rules:
-
Policy version: Select the appropriate version (e.g., 1.0.6 latest)
-
Rule of application: Choose how the policy should be applied:
- All runtimes: Apply to all APIs with Flex and Mule (4.1.1 and above)
- Flex gateways only: Apply only to Flex gateways (note: this version may not support implementations)
- Mule gateways only: Apply only to Mule gateways
- Version range: Specify the Mule runtime version range (e.g., from 4.1.1)
- Java Versions: Choose to apply to all Java versions or specify particular versions
Benefits of Automated Policy
- Centralized Management: Manage all your API monitoring from a single policy configuration
- Consistent Data Masking: Apply the same masking rules across all your APIs
- Unified Dashboard: View all API traffic in one consolidated view on the Treblle platform
- Reduced Maintenance: No need to individually configure each API
- Automatic Coverage: New APIs automatically inherit the policy configuration
Note
When using automated policies, all APIs within the specified scope will be monitored under the same Treblle workspace. This is ideal for organizations that want a unified view of their API ecosystem.
Masking Fields
To mask fields in MuleSoft:
- Go to your API
- Navigate to Policies
- Click Edit Treblle Policy Configuration
- Add Masking Fields and separate them with commas
This is how it will look in the Treblle dashboard:
Masking the Entire Payload
To mask the entire payload in MuleSoft:
- Check the Mask Payload option while adding a policy to your API
- View the masked payload in your API requests - it will appear like this in your Treblle dashboard:
When the “Mask Payload” option is enabled, the entire request and response payload will be masked with asterisks (*****) while preserving the structure and length of the original data.
How It Works
The Treblle MuleSoft policy acts as a middleware that:
- Intercepts incoming API requests before they reach your implementation
- Captures request payloads and headers without modifying them
- Sends the data asynchronously to Treblle’s servers
- Allows the request to continue to your API implementation without delay