Home » Building a SaaS Product » API Endpoints

How to Build API Endpoints for Your SaaS Product

API endpoints are the communication layer between your SaaS frontend and your backend logic. Each endpoint receives a request, processes it, and returns a response. The platform handles routing, authentication, and billing automatically, so you only need to write the function that does the actual work.

How API Endpoints Work on the Platform

Every custom app on the platform gets its own set of API endpoints through the app commands system. When you define a command in your app configuration, the platform creates a secure API endpoint that your frontend, mobile app, or external integrations can call.

The request flow works like this:

Every command function follows the same signature: $result = yourFunction($accountID, $jsonData). The platform gives you the authenticated account ID so you always know which customer is making the request, and the JSON data contains whatever your frontend sent.

Designing Your API

A well-designed API for a SaaS product follows predictable patterns. For each data type your product manages, you typically need these endpoints:

For a helpdesk SaaS, your ticket endpoints might look like: createTicket, getTicket, listTickets, updateTicket, deleteTicket. Each one is a separate command in your app configuration.

Handling Input and Validation

Your command functions receive raw JSON data from the caller. Always validate before using it:

Good validation at the API layer means your frontend and your data stay clean. Never trust that the frontend has already validated the data, because API endpoints can be called directly by anyone with an API key.

Structuring Your Response

Every endpoint should return a consistent response format. A common pattern:

Consistent response formats make your frontend code simpler because every API call can be handled with the same response parsing logic. Include enough detail in error messages for the frontend to show useful feedback, but never expose internal details like database field names or stack traces.

Combining Multiple Operations

Sometimes a single user action requires multiple database operations. For example, creating an order might need to create the order record, update inventory counts, and send a confirmation email. You can handle this in one endpoint by performing all operations sequentially in your command function, or you can use background jobs for the parts that do not need to complete before the user gets a response.

For more complex multi-step operations, the platform's workflow automation system lets you chain multiple commands together with conditional logic, so one API call can trigger an entire business process.

API Security

The platform handles the main security concerns automatically:

For your part, focus on input validation (described above) and making sure your functions never return data belonging to a different account. Since the platform passes the authenticated account ID to every function call, this is straightforward as long as you always use that ID for database queries rather than accepting an account ID from the request body.

Build your SaaS API endpoints with built-in authentication, billing, and routing. Focus on your product logic, not plumbing.

Get Started Free