Product
Enterprise
Solutions
DocumentationPricing
Resources
Book a DemoSign InGet Started
Product
Solutions
Solutions
Blog |How to Build Your First API on MuleSoft and Monitor It with Treblle

How to Build Your First API on MuleSoft and Monitor It with Treblle

API Design  |  Jul 31, 2025  |  10 min read  |  By Rahul Khinchi  |  Reviewed by Pratim Maloji Bhosale

Summarize with
How to Build Your First API on MuleSoft and Monitor It with Treblle image

Rahul Khinchi is a Developer Advocate at Treblle, where he focuses on improving API workflows and developer experience. He writes technical content on API observability, security, and governance, and builds open-source tools to demonstrate real-world API use cases. Rahul has spoken at developer meetups and universities, and previously held developer advocacy roles at Syncloop. He was selected for Google Summer of Code in 2022 and has led community initiatives supporting thousands of beginners in open source.

Just getting started with MuleSoft and want to track your API traffic? I’ve been there. Here’s the exact setup I used to connect Treblle with MuleSoft, from proxy creation to real-time monitoring, so you can skip the confusion and get results in minutes.

If you're just getting started with MuleSoft and wondering how to track your API traffic with Treblle, this guide is for you. I recently worked on integrating Treblle with MuleSoft from scratch. I'll walk you through the exact steps I followed.

I've been tasked with setting up Mulesoft with Treblle, and I'm overwhelmed. There are so many moving parts—where do you even start?

After some trial and error (okay, a lot of error), I figured out a straightforward approach that got me from zero to a fully monitored API in about 15 minutes. Here's exactly what I did, including the mistakes I made, so you don't have to.

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

My Setup (You'll Need This Too)

Before anything, I made sure I had:

  • Anypoint Studio (v7.21 or later) - MuleSoft's IDE

  • Java 17+

  • MuleSoft account with API Manager access

  • Treblle account with API Key and SDK Token

  • Maven 3.8+ - for building the policy

Don't have Treblle credentials? No worries! I created a free project atTreblle.com and grabbed my API Key and SDK Token in less than a minute.

Tip: Check this documentation to learn more about how to get the API Key and SDK Token.

I didn't need to write a single line of code. We'll use a mock API to simulate real traffic, which means you can follow along.

I decided to:

  1. Create a simple API proxy that connects to a mock data source

  2. Deploy it to MuleSoft's cloud infrastructure

  3. Add Treblle to track every request

  4. Test everything with real traffic

This way, I could see immediate results and understand how everything connects before diving into more complex implementations.

Step 1: Creating My First API Instance

Accessing the API Manager

  1. Log in to Anypoint Platform

  2. Navigate to API Manager

  3. Click the Add API button

  4. Select Add new API

Configuring the API Runtime

Runtime Selection:

  • Choose Mule Gateway (API gateway embedded in Mule runtime)

  • Select Deploy a proxy application

  • Choose CloudHub 2.0 as the target type

Runtime Configuration:

  • Target Type: CloudHub 2.0

  • Select Space: Choose your preferred region (e.g., Cloudhub-US-East-2)

  • Runtime Version: 4.9.7 (or latest available)

  • Java Version: Java 17 (for better performance)

  • Proxy App Name: user-management-api-proxy (use lowercase, numbers, and hyphens only)

Step 2: API Configuration

API Details

  • API Name: User Management API

  • Asset Types: HTTPS API (You can choose from HTTP, REST, and SOAP)

Downstream Configuration (Inbound Traffic)

The downstream configuration (how requests come into your API) can mostly be left as defaults. The critical part is the upstream configuration, where your API proxy will forward requests.

But you can configure it if desired:

  • Protocol: HTTPS (recommended for production)

  • Inbound TLS: Leave default (no custom TLS context needed)

  • Port: 8081

  • Base Path: /api/users

  • Client Provider: Anypoint

  • Instance Label: user-management-v1 (recommended for multiple API versions)

Upstream Configuration (Your Backend Service)

  • Upstream URL: https://mocki.io/v1/45022130-8f2d-49ce-8462-db1297dcf065

  • Outbound TLS: Leave default (no custom TLS context needed)

Note: We're using a mock API for demonstration. In production, this would be your actual CloudHub application URL, like https://user-management-api-yourname.us-e1.cloudhub.io

Creating Your Own Mock API (Optional)

This is a mock API that returns realistic user data. It is perfect for testing without having to build an actual backend.

If you want to create a custom mock API:

  1. Go to Mocki.io

  2. Scroll down to the Free API Editor section

  3. Create a response body and click Create API

  4. Copy the generated URL

Step 3: Review and Deploy

  1. Review all configurations in the Review section

  2. Click Save & Deploy

  3. Wait for the proxy application to deploy (this may take a few minutes)

  4. Once deployed, note the Proxy URL - this will be your public API endpoint

After clicking "Save & Deploy," I learned the first rule of cloud deployments: patience. Everything spun up in about 2 minutes, which felt like forever when you're excited to see results.

Step 4: Monitoring Deployment and Getting the Public Endpoint

  1. In Runtime Manager, you'll see your proxy application user-management-api-proxy

  2. Wait for the status to show Running with a green indicator

  3. The deployment typically takes 1-2 minutes

  4. Once active, you'll see the Public Endpoint in the application details:

https://user-management-api-proxy-5q5pek.5ec6y6-3.usa.e2.cloudhub.io
  1. Copy this URL - this is your public API endpoint for testing

Success! I got back a JSON response with mock user data. The proxy was working, but I could not see what was happening. That's where I will use Treblle.

Part 5: Setting Up Treblle

Get Your Treblle Credentials

  1. Log in to your Treblle Dashboard

  2. Create a new project or use an existing one

  1. Copy your API Key and Project ID

Step 6: Creating and Deploying the Treblle Policy

Here's where things got interesting.

Unlike built-in policies, Treblle's monitoring policy must be deployed to your organization's Exchange first. This is a one-time setup, but it involves some command-line work.

Obtain Your Organization ID

  1. Navigate to Anypoint Platform Business Groups

  2. Select your business group

  3. Note the Business Group ID from the URL or page details

Note: The Business Group ID is a unique identifier that looks like: 68ef933a-6a4e-4d9d-8262-9c2a93c11111

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Clone and Configure the Treblle Policy

  1. Then I cloned the Treblle repository and made some configuration changes:
git clone https://github.com/Treblle/treblle-mulesoft.git
cd treblle-mulesoft
  1. I updated the treblle-policy/pom.xml file with my Organization ID and configured my Maven settings with my MuleSoft credentials.
<groupId>{BUSINESS_GROUP_ID}</groupId>
  1. Configure Maven Settings: Navigate to samples/.m2/settings.xml and 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.

Build and Deploy the Policy

  1. Navigate to the treblle-policy directory:
cd treblle-policy
  1. Build the policy:
mvn -s ../samples/.m2/settings.xml clean package
  1. 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.

Verify Policy Installation

  1. Visit Anypoint Exchange

  2. Search for "treblle policy"

  3. Confirm the policy is available in your organization

  4. The policy should appear with version 1.0.6 and display as a Custom Policy

Step 8: Applying the Treblle Policy to Your API

Apply the Treblle Policy

  1. Go to API Manager in Anypoint Platform

  2. Find your User Management API instance

  3. Click on your API instance

  1. Go to the Policies tab.

  2. Click Apply New Policy

  3. Search for "treblle-policy"

  4. Choose treblle-policy from the list of available policies

Configure the Policy

Configure the policy with your Treblle credentials:

  • API Key: Enter your Treblle Project ID

  • SDK Token: Enter your Treblle API Key

  • Mask Keywords: (Optional) email,password,ssn - comma-separated sensitive fields to mask

  • Mask Payload: (Optional) false - set to true to mask entire payloads

Apply and Test

  1. Click Apply to save the policy configuration

  2. Wait for the policy to be applied (usually takes 30-60 seconds)

  3. The policy should appear in your Policies list as "Applied."

After applying the policy, I waited about 30 seconds for it to take effect. Then I started hitting my API endpoint with different types of requests.

Step 9: Monitoring Your API in Action

Test Your API Proxy

Test the proxy endpoint to ensure it's working:

curl https://user-management-api-proxy-5q5pek.5ec6y6-3.usa.e2.cloudhub.io

Or use Aspen for fast API testing:

  • Open Aspen in your browser

  • Enter your proxy URL

  • Test different HTTP methods (GET, POST, PUT, DELETE)

  • View real-time responses

Step 10: Explore Your Treblle Dashboard

  1. Go to your Treblle Dashboard

  2. Select your project

  3. You should see real-time data including:

    • Request/Response logs with full payloads

    • Performance metrics (response times, status codes)

    • Error tracking for any failed requests

    • Usage analytics showing endpoint popularity

And then I saw it happen in real-time:

What Blew My Mind

  • Every request appeared instantly in my Treblle dashboard

  • Response times measured in milliseconds (my API was fast!)

  • Complete request/response data - headers, payloads, everything

  • Beautiful visualizations showing usage patterns

I could literally watch the data flow:

  1. My curl command hits the API Manager proxy

  2. Treblle policy captures the request

  3. Request forwards to mocki.io

  4. Response flows back through the proxy

  5. Treblle captures the complete cycle

Lessons Learned

What Worked Well

  • Using a mock API meant I could focus on the monitoring setup without worrying about backend complexity.

  • The proxy approach gave me immediate results with minimal configuration

  • Treblle's policy captured everything I needed without impacting performance

What I'd Do Differently

  • I should have checked my Exchange permissions before attempting the policy deployment.

  • Testing the upstream URL directly first would have saved some debugging time.

  • Setting up masking keywords from the start is better than adding them later.

Unexpected Benefits

  • The proxy pattern works great for legacy systems that don't have built-in monitoring.

  • Having real-time visibility immediately changed how I think about API performance.

  • The detailed request logs made debugging so much easier

The Bottom Line

Building my first API with MuleSoft and monitoring it with Treblle was eye-opening. The combination of MuleSoft's robust API management platform and Treblle's comprehensive monitoring gave me everything I needed to build, deploy, and observe a production-ready API.

But here's the real insight: monitoring from day one changes everything. Instead of deploying and hoping for the best, I could see exactly what was happening, catch issues early, and optimize based on real data.

If you're thinking about diving into API development, do yourself a favor: set up monitoring from the start. Your future self will thank you when you don't understand why your API is slow or who's using it.

What's Next for You

If you're in a similar situation, here's what I'd recommend:

Start with this exact setup. Don't try to build something complex right away. Get the proxy working, add monitoring, and understand the data flow.

Focus on the monitoring first. You can always replace the mock API with a real backend later, but having visibility from day one is invaluable.

Use the data to drive decisions. After a week of monitoring data, you'll be amazed at what you learn about your API usage patterns.

Gradually add complexity. Authentication, rate limiting, and caching - add these features one at a time so you can measure their impact.

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Related Articles

How to Send and Receive Data in a REST API coverAPI Design

How to Send and Receive Data in a REST API

Learn how to send and receive data in REST APIs using query strings, headers, JSON bodies, and form-data. This guide covers practical examples across popular frameworks, and shows you how to build secure, reliable APIs from request to response.

How to Add Pagination to Your REST API coverAPI Design

How to Add Pagination to Your REST API

Pagination is key to building fast, scalable REST APIs. It improves performance, reduces server load, and helps users navigate large datasets easily. This guide covers common pagination strategies, implementation tips, and best practices for clean, efficient API design.

Why Your API Performance Is Costing You Users (and How to Fix It) coverAPI Design

Why Your API Performance Is Costing You Users (and How to Fix It)

APIs are the backbone of modern software, but speed, reliability, and efficiency do not happen by accident. This guide explains what API performance really means, which metrics matter, and how to optimize at every layer to meet the standards top platforms set.

© 2025 Treblle. All Rights Reserved.
GDPR BadgeSOC2 BadgeISO BadgeHIPAA Badge