Collections Examples
Complete JavaScript examples for working with Payload CMS collections organized by collection type.
Available Collections
- Users - Create, query, and update user accounts with different roles
- Products - Create products, publish, search by category, price range, and HCPCS codes
- Orders - Create orders, manage status (approve, ship, cancel), and query by customer
- Transactions - Record transactions, get history, and track refunds
- Payment Methods - Add, update, and manage customer payment methods
- Care Management - Create care lists, manage patient records, and overseer relationships
- Messaging - Send messages, manage inbox, mark as read, and delete
Quick Start
All examples use the same authentication pattern:
const token = "YOUR_JWT_TOKEN";
const response = await fetch('https://api.picoshealth.com/v1/users', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
});
Error Handling
Implement robust error handling for all requests:
const apiRequest = async (url, options = {}) => {
try {
const response = await fetch(url, options);
if (!response.ok) {
const errorData = await response.json();
throw new Error(`API Error: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Request failed:', error.message);
throw error;
}
};
Rate Limiting
Respect rate limits (100 requests/minute) with exponential backoff:
const retryWithBackoff = async (fn, maxRetries = 3) => {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
const delay = Math.pow(2, i) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
}
}
};
Last Updated: June 22, 2026