Appearance
Exercise 2: Build a MuleSoft App
In this exercise, you’ll build a hotel-reservation API in Anypoint Code Builder, enrich it with Topic Center metadata, validate it with governance rulesets, publish it to Exchange, scaffold the implementation, and deploy it to CloudHub.
Step 1: Launch Anypoint Code Builder
Log into your Anypoint account at anypoint.mulesoft.com.
Click on the Navigation Toggle to open the Sidebar.
Click on Anypoint Code Builder.
TIP
You can also use Desktop IDE by downloading VSCode Studio. Refer documentation for more information.
Click Terms and Conditions.
Read the full Terms and Conditions, set I accept the Anypoint Code Builder beta Terms and Conditions. to True, and click Get Access.
Click Launch to open Anypoint Code Builder.
TIP
It could take a few minutes to build and open your virtual environment.
Step 2: Create a Topic-Enabled API
Select Design an API under Quick Actions.
Configure the API as follows:
Field Value Enable this API for Agent Topic and Actions True
Project Name coral-cloud-reservation
Project Location default API Type default API Specification OAS 2.0 (YAML)
Business Group Leave blank Click Create Project.
Set Trust the authors… to True and click Yes, I trust the authors.
Click on your Profile Icon and select Sign in with Anypoint Platform…
If prompted Do you want code-server to open the external website?, click Open.
Back in Anypoint Code Builder, select your available Business Group.
TIP
You should be automatically logged in, however, if prompted to sign in, use your credentials from Exercise 1.
Replace the placeholder in
coral-cloud-reservations.yaml
with the following API Design Specification:yamlopenapi: 3.0.0 info: version: 1.0.0 title: Hotel Reservations API description: API to manage hotel room bookings, check availability, and apply loyalty benefits. x-sfdc: agent: topic: name: Hotel_Room_Reservation classificationDescription: This API allows agents to book, modify, and cancel hotel reservations, as well as apply loyalty upgrades. scope: Your job is to assist customers in booking hotel rooms based on their preferences, loyalty status, and availability. You should also be able to recommend upgrades if the customer qualifies. instructions: - Always check the customer's loyalty status before finalizing the booking. - If the customer asks to create a reservation, check for a check-in date, checkout date, roomType, or any special requests. - If the preferred room type is unavailable, suggest alternative options with similar amenities. - Never confirm a reservation without validating payment information. - If the customer qualifies for an upgrade, apply it automatically and notify them. paths: /reservations: post: summary: Create a new hotel reservation description: Book a hotel room with specified preferences and apply loyalty upgrades if eligible. operationId: reservationCreate x-sfdc: agent: action: publishAsAgentAction: true parameters: - in: query name: source required: false schema: type: string description: Source of the reservation request (e.g., web, mobile app, agent). x-sfdc: agent: action: isUserInput: true requestBody: required: true description: Customer reservation details including stay dates, room type, and special requests. content: application/json: schema: additionalProperties: false type: object x-sfdc: agent: action: isUserInput: true properties: customerId: type: string description: Unique identifier of the customer making the reservation. checkInDate: type: string description: Date of check-in for the reservation. checkOutDate: type: string description: Date of check-out for the reservation. roomType: type: string description: Preferred room type for the reservation. specialRequests: type: string description: Additional requests like pillow type or air freshener choice. responses: "201": description: Reservation successfully created. content: application/json: schema: additionalProperties: false type: object x-sfdc: agent: action: isDisplayable: true privacy: isPii: true properties: reservationId: type: string description: Unique identifier of the created reservation. upgradeApplied: type: boolean description: Indicates whether a loyalty-based upgrade was applied. totalPrice: type: number description: Final price after applying any discounts or upgrades. /reservations/{reservationID}: get: summary: Retrieve reservation details description: Get details of a specific reservation by ID. operationId: reservationRetrieve x-sfdc: agent: action: publishAsAgentAction: true parameters: - in: path name: reservationID required: true schema: type: string description: Unique identifier of the reservation to be retrieved. x-sfdc: agent: action: isUserInput: true responses: "200": description: Reservation details retrieved successfully. content: application/json: schema: additionalProperties: false x-sfdc: agent: action: isDisplayable: true privacy: isPii: true type: object properties: reservationId: type: string description: Unique identifier of the reservation. customerId: type: string description: Unique identifier of the customer who booked the reservation. roomType: type: string description: Type of room booked for the reservation. checkInDate: type: string description: Check-in date of the reservation. checkOutDate: type: string description: Check-out date of the reservation. upgradeApplied: type: boolean description: Indicates whether a loyalty-based upgrade was applied.
Save the file (CMD+S on Mac or CTRL+S on PC).
Review the topic generated by the YAML and click Apply.
Step 3: Run Governance Rulesets
In the Sidebar, open Governance Rulesets.
Run SF API Topic & Action Enablement Ruleset and verify readiness.
If configured correctly, the output will read:
No conformance issues found after running validations with selected rules or rulesets.
Step 4: Publish Your API to Exchange
In Anypoint Code Builder, open the command palette (CMD+SHIFT+P on Mac or CTRL+SHIFT+P on PC).
Search for Publish API and click MuleSoft: Publish API Project to Exchange.
In the Publish API Project to Exchange dialog, keep defaults and click Publish.
Set both Asset Version and API Version to 1.0.0, then click Publish.
When prompted to implement
coral-cloud-reservation
, select Yes.Set the Project Name to
coralcloud-hotel-reservation-impl
.Leave Target Folder blank and press OK.
Accept the latest Java Version and Version by pressing return.
Step 5: Building the Mule Application
You will be taken to the new project
CORALCLOUD-HOTEL-RESERVATION-IMPL
.Open
coralcloud-hotel-reservation-impl.xml
insidesrc/main/mule/
.Open the Flow List.
Select the get:/reservations flow.
Click the + under the Logger element to add a new connector.
Search for Transform with output JSON and add it.
In the Transform Message element, paste this DataWeave script into Inline Script:
dw%dw 2.0 output application/json --- { reservationId: vars.reservationID, customerId: "CUST001", roomType: "Suite", checkInDate: "2025-03-28", checkOutDate: "2025-04-02", upgradeApplied: true, specialRequests: "Ocean view, foam pillows" }
Step 6: Creating an API Instance
Open a new browser tab and go to Anypoint Platform.
In the Sidebar, open API Manager.
Click Add API → Add new API.
Set Runtime to Mule Gateway.
TIP
You can also use Flex Gateway and Managed Flex Gateway for the APIs that are hosted externally.
Leave Proxy type and Mule version default. Click Next.
Select
coralcloud-hotel-reservation
.Leave defaults and click Next.
Leave Instance label blank and click Next.
Leave Upstream URL blank and click Next.
Review and click Save.
Note your API Instance ID for later.
Step 7: Adding Auto-Discovery
Return to Anypoint Code Builder.
Open
coralcloud-hotel-reservation-impl.xml
insrc/main/mule/
.Below
</http:listener-config>
, add:xml<api-gateway:autodiscovery apiId="<API_INSTANCE_ID>" ignoreBasePath="true" doc:name="API Autodiscovery" doc:id="22e21554-387e-44c3-9f08-3863b610633c" flowRef="<MAIN_FLOW_NAME>" />
Replace
<API_INSTANCE_ID>
with your ID from the previous step and replace<MAIN_FLOW_NAME>
with your main flow name. You can find the flow name under the Flow List.Save the file (CMD+S or CTRL+S).
Step 8: Deploy MuleSoft App to CloudHub
- With
coral-cloud-reservation.xml
open, click the Rocket icon. - Select CloudHub 2.0.
- Choose Cloudhub-US-East-2 – Shared Space.
- Select Sandbox.
- Pick the latest Java Runtime.
- Set Asset Version to 1.0.0.
- Click Open in Runtime Manager.
Step 9: Configure Your API Secrets
In a new tab, go to Anypoint Platform → Access Management → Business Groups.
Select your Business Group and copy the Client ID and Client Secret.
Return to the Runtime Manager tab.
Click
coralcloud-hotel-reservation-impl
.Open the Properties tab and add:
Key Value anypoint.platform.client_id
Your Client ID anypoint.platform.client_secret
Your Client Secret Click Apply Changes.
Copy the Public Endpoint.
Step 10: Update API Instance
- In API Manager, open the
coral-cloud-reservation
API. - Click Edit.
- Update both Consumer Endpoint and Upstream URL to your Public Endpoint, appending
/api/
. - Click Save and confirm status is Active.
Summary
In this exercise, you:
- Launched Anypoint Code Builder and accepted the beta terms
- Created and published a topic-enabled API to Exchange
- Built and deployed a Mule application with auto-discovery
- Configured runtime secrets for secure platform access
- Updated your API instance in API Manager
With your MuleSoft app live in CloudHub and integrated into API Manager, you’re now ready to sync it into Salesforce’s API Catalog and activate agent actions in the next exercise.