API Overview
Mars provides a comprehensive REST API for integrating your applications with external systems.
Authentication
All API requests require authentication using API keys.
Getting Your API Key
- Navigate to Settings > API Keys
- Click "Generate New Key"
- Copy and store securely (won't be shown again)
- Use in request headers
Authentication Header
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Base URL
https://api.mars.new/v1
Rate Limits
- Free Plan: 1,000 requests/hour
- Pro Plan: 10,000 requests/hour
- Enterprise: Custom limits
Rate limit headers included in every response:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200
Common Endpoints
Applications
List all apps
GET /apps
Get app details
GET /apps/{app_id}
Create new app
POST /apps
{
"name": "My App",
"description": "App description"
}
Forms
List forms
GET /apps/{app_id}/forms
Get form schema
GET /apps/{app_id}/forms/{form_id}
Submit form data
POST /apps/{app_id}/forms/{form_id}/submissions
{
"field1": "value1",
"field2": "value2"
}
Data Tables
Query records
GET /apps/{app_id}/tables/{table_id}/records
?filter=status:active
&sort=-created_at
&limit=50
Create record
POST /apps/{app_id}/tables/{table_id}/records
{
"title": "New Task",
"status": "active"
}
Update record
PUT /apps/{app_id}/tables/{table_id}/records/{record_id}
{
"status": "completed"
}
Delete record
DELETE /apps/{app_id}/tables/{table_id}/records/{record_id}
Response Format
All responses are JSON formatted.
Success Response
{
"success": true,
"data": {
"id": "123",
"name": "Example"
},
"meta": {
"timestamp": "2024-01-01T12:00:00Z"
}
}
Error Response
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid field value",
"details": {
"field": "email",
"issue": "Invalid email format"
}
}
}
Error Codes
| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED |
401 | Invalid or missing API key |
FORBIDDEN |
403 | Insufficient permissions |
NOT_FOUND |
404 | Resource doesn't exist |
VALIDATION_ERROR |
400 | Invalid request data |
RATE_LIMIT_EXCEEDED |
429 | Too many requests |
SERVER_ERROR |
500 | Internal server error |
Webhooks
Subscribe to events in your apps:
Available Events
form.submittedrecord.createdrecord.updatedrecord.deletedworkflow.completeduser.added
Webhook Configuration
POST /webhooks
{
"url": "https://your-server.com/webhook",
"events": ["form.submitted", "record.created"],
"app_id": "app_123"
}
Webhook Payload
{
"event": "form.submitted",
"timestamp": "2024-01-01T12:00:00Z",
"app_id": "app_123",
"data": {
"form_id": "form_456",
"submission_id": "sub_789",
"values": {
"field1": "value1"
}
}
}
SDKs
Official SDKs available for:
- JavaScript/TypeScript
- Python
- Ruby
- PHP
- Go
JavaScript Example
import { MarsClient } from '@mars/sdk';
const client = new MarsClient({
apiKey: 'your_api_key'
});
// Create a record
const record = await client.tables.create('tasks', {
title: 'New Task',
status: 'active'
});
// Query records
const records = await client.tables.query('tasks', {
filter: { status: 'active' },
sort: '-created_at',
limit: 10
});
Best Practices
-
Use API Keys Securely
- Store in environment variables
- Never commit to source control
- Rotate keys regularly
-
Handle Rate Limits
- Implement exponential backoff
- Cache responses when possible
- Use webhooks instead of polling
-
Error Handling
- Check status codes
- Log errors for debugging
- Provide user-friendly messages
-
Pagination
- Use limit/offset parameters
- Don't fetch more than needed
- Process in batches