Make your first API call
Authenticate with EmuView and query records using HTTP requests and the TypeScript SDK.
#Make your first API call
By the end of this guide, you'll know how to authenticate with EmuView and perform CRUD operations using both raw HTTP and the TypeScript SDK.
#Prerequisites
- An EmuView project with at least one collection (see Create your first collection)
- An API key or user credentials
#Steps
#1. Choose an authentication method
EmuView supports two authentication methods. Both use the Authorization: Bearer header.
| Method | Token format | Best for |
|---|---|---|
| API key | sk-your-api-key |
Server-side scripts, CI/CD, admin tools |
| Session token | eyJhbGciOi... |
Client-side apps after user sign-in |
For this guide, use your API key. If you don't have one, create it in Settings → API Keys.
#2. Create a record
Insert a product into the products collection:
#HTTP
curl -X POST https://your-api.example.com/api/v1/collections/products/records \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"title": "Premium Widget",
"price": 49.99,
"status": "published",
"description": "<p>A high-quality widget for professionals.</p>"
}'
Response (201 Created):
{
"id": "b10b01964f804a55b140be7dad738c8f",
"title": "Premium Widget",
"price": 49.99,
"status": "published",
"description": "<p>A high-quality widget for professionals.</p>",
"created_at": 1718900000,
"updated_at": 1718900000,
"created_by": "usr_abc123",
"updated_by": "usr_abc123"
}
#SDK
import { EmuView } from '@emuview/sdk';
const sdk = new EmuView({
url: 'https://your-api.example.com',
auth: { apiKey: 'sk-your-api-key' }
});
const product = await sdk.collection('products').create({
title: 'Premium Widget',
price: 49.99,
status: 'published',
description: '<p>A high-quality widget for professionals.</p>'
});
console.log(`Created product ${product.id}: ${product.title}`);
#3. Read records
Fetch a list of records with filtering and sorting:
#HTTP
curl "https://your-api.example.com/api/v1/collections/products/records?filter=%7B%22status%22:%22published%22%7D&sortBy=created_at&order=desc&limit=10" \
-H "Authorization: Bearer sk-your-api-key"
The filter parameter is a URL-encoded JSON object. The shorthand {"status": "published"} is equivalent to {"status": {"_eq": "published"}}.
#SDK
const results = await sdk.collection('products').list({
filter: { status: 'published' }, // Shorthand for { status: { _eq: 'published' } }
sortBy: '-created_at', // Prefix with "-" for descending
limit: 10
});
console.log(`Found ${results.total} published products`);
for (const product of results.data) {
console.log(` ${product.title} — $${product.price}`);
}
Response shape:
{
"data": [
{
"id": "b10b01964f804a55b140be7dad738c8f",
"title": "Premium Widget",
"price": 49.99,
"status": "published",
"created_at": 1718900000,
"updated_at": 1718900000
}
],
"total": 1,
"page": 1,
"limit": 10,
"hasMore": false
}
#4. Update a record
Change the price and status of a record. Send only the fields you want to update:
#HTTP
curl -X PATCH https://your-api.example.com/api/v1/collections/products/records/b10b01964f804a55b140be7dad738c8f \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"price": 39.99}'
#SDK
const updated = await sdk.collection('products').update('b10b01964f804a55b140be7dad738c8f', {
price: 39.99
});
console.log(`New price: $${updated.price}`); // New price: $39.99
#5. Delete a record
By default, delete performs a soft delete (sets deleted_at). Add ?permanent=true to remove the row from the database.
#HTTP
# Soft delete (default)
curl -X DELETE https://your-api.example.com/api/v1/collections/products/records/b10b01964f804a55b140be7dad738c8f \
-H "Authorization: Bearer sk-your-api-key"
# Permanent delete
curl -X DELETE "https://your-api.example.com/api/v1/collections/products/records/b10b01964f804a55b140be7dad738c8f?permanent=true" \
-H "Authorization: Bearer sk-your-api-key"
#SDK
// Soft delete
await sdk.collection('products').delete('b10b01964f804a55b140be7dad738c8f');
// Permanent delete
await sdk.collection('products').delete('b10b01964f804a55b140be7dad738c8f', { permanent: true });
#What you learned
- How to authenticate API requests with a Bearer token
- How to create, read, update, and delete records
- The difference between soft delete and permanent delete
- How to use filter shorthand and sort direction prefixes in the SDK
#Next steps
- Filtering records — Learn all filter operators and combine complex queries
- Relations and expand — Link collections and query nested data
- SDK reference — Explore the full SDK API