telepath_api Usage Guide
This document describes how to interact with the telepath_api collection in PocketBase, including obtaining a token for authentication, the required fields, and performing CRUD and realtime operations.
1. Base URL
All requests use the base URL:
https://pocketbase.telepathcare.com
The general endpoint for the telepath_api collection is:
/api/collections/telepath_api/records
2. Authentication & Getting a Token
Admin Authentication
- Log In as an admin (example using JavaScript SDK):
import PocketBase from 'pocketbase';
const pb = new PocketBase('https://pocketbase.telepathcare.com');
await pb.admins.authWithPassword('admin@example.com', 'yourAdminPassword');
// The pb.authStore.token is your admin token
const token = pb.authStore.token;
- Use the Token in requests:
- With the JavaScript SDK, this is automatic.
- With direct HTTP calls, include the header:
Authorization: TOKEN
User Authentication (If Applicable)
- Log In via the users collection:
await pb.collection('users').authWithPassword('user@example.com', 'password');
const token = pb.authStore.token;
- Use the Token similarly (SDK or header).
3. Fields in telepath_api
This is the complete list of fields you may include when creating or updating a record. Fields in bold are required (unless your server's rules differ).
- firstName (String, e.g. "John")
- lastName (String, e.g. "Doe")
- email (String, valid email, e.g. "john@example.com")
- phoneNumber (String, e.g. "1234567890")
- tos (Boolean, indicates Terms of Service acceptance)
- dob (String, ISO datetime, e.g. "2022-01-01T10:00:00.123Z")
- gender (String, e.g. "male", "female", "other")
- weight (Number, e.g. 150)
- address (String, e.g. "123 Main St.")
- city (String, e.g. "Springfield")
- state (String, e.g. "IL")
- zip (Number, e.g. 12345)
- country (String, optional, e.g. "USA")
- preName (String, optional, e.g. "Mr.")
- refCode (String, optional, e.g. "REF123")
- preg (Boolean, optional)
- glp1 (Boolean, optional)
- WeightLossGoals (String, optional, e.g. "Lose 20 lbs")
- allergies (String, optional, e.g. "Peanuts, Shellfish")
- medicalConditions (String, optional, e.g. "Diabetes, Hypertension")
- medications (String, optional, e.g. "Metformin, Lipitor")
- requestedProductName (String, optional)
- requestedPharmacy (String, optional)
- idDocument (File or Array of Files, required; set to null to remove)
- selfie (File or Array of Files, required; set to null to remove)
- heightFeet (String, optional, e.g. "5")
- heightInches (String, optional, e.g. "11")
- historyFastHeartbeat (Boolean, optional)
- notes (String, optional)
- back (File or Array of Files, required; set to null to remove)
- status (String, optional, e.g. "Pending", "Approved")
- thyroidCancer (Boolean, optional)
- recentBariatricSurgery (Boolean, optional)
- chronicConditions (Boolean, optional)
- type1 (Boolean, optional)
- cancer (Boolean, optional)
- mens2 (Boolean, optional)
- glp1Reaction (Boolean, optional)
Note: Fields marked as required must be included for creation or update. File uploads (idDocument, selfie, back) require multipart/form-data if sending files.
4. Listing & Searching (GET)
Endpoint:
GET /api/collections/telepath_api/records
Supports query parameters like page, perPage, sort, filter, expand, fields, etc.
Examples using JavaScript SDK:
// Paginated List (page 1, up to 50 records)
const resultList = await pb.collection('telepath_api').getList(1, 50, {
filter: 'created >= "2022-01-01 00:00:00" && someField1 != someField2',
});
// Get all records unpaginated, sorted by creation date (descending)
const allRecords = await pb.collection('telepath_api').getFullList({
sort: '-created',
});
// Get the first record matching a filter, expanding relations
const firstRecord = await pb.collection('telepath_api')
.getFirstListItem('someField="test"', {
expand: 'relField1,relField2.subRelField',
});
5. Creating Records (POST)
Endpoint:
POST /api/collections/telepath_api/records
Must include all required fields in the request body. Files must be sent via multipart/form-data if you're uploading them.
Example (JavaScript SDK):
const data = {
firstName: "John",
lastName: "Doe",
email: "john@example.com",
phoneNumber: "1234567890",
tos: true,
dob: "2022-01-01T10:00:00.123Z",
gender: "male",
weight: 150,
address: "123 Main St",
city: "Springfield",
state: "IL",
zip: 12345,
country: "USA",
preName: "Mr.",
refCode: "REF123",
preg: false,
glp1: false,
WeightLossGoals: "Lose 20 lbs",
allergies: "Peanuts",
medicalConditions: "Hypertension",
medications: "Lisinopril",
requestedProductName: "Product A",
requestedPharmacy: "Pharmacy XYZ",
idDocument: [/* File object(s) */],
selfie: [/* File object(s) */],
back: [/* File object(s) */],
heightFeet: "5",
heightInches: "11",
historyFastHeartbeat: false,
notes: "No special notes",
status: "Pending",
thyroidCancer: false,
recentBariatricSurgery: false,
chronicConditions: true,
type1: false,
cancer: false,
mens2: false,
glp1Reaction: false
};
// If uploading files, make sure you're using multipart/form-data
const record = await pb.collection('telepath_api').create(data);
6. Viewing a Single Record (GET)
Endpoint:
GET /api/collections/telepath_api/records/:id
Replace :id with the record's ID. Query params like expand or fields can also be used.
Example (JavaScript SDK):
const record = await pb.collection('telepath_api').getOne('RECORD_ID', {
expand: 'relField1,relField2.subRelField',
});
7. Updating a Record (PATCH)
Endpoint:
PATCH /api/collections/telepath_api/records/:id
Replace :id with the record's ID. You must include all required fields (unless partial updates are allowed by your server rules).
Example (JavaScript SDK):
const updateData = {
firstName: "Jane",
lastName: "Smith",
email: "jane@example.com",
phoneNumber: "0987654321",
tos: true,
dob: "2022-02-15T12:00:00.456Z",
gender: "female",
weight: 140,
address: "456 Another Road",
city: "Metropolis",
state: "NY",
zip: 54321,
country: "USA",
preName: "Ms.",
refCode: "UPD123",
preg: false,
glp1: true,
WeightLossGoals: "Maintain weight",
allergies: "None",
medicalConditions: "Migraines",
medications: "Tylenol",
requestedProductName: "Product B",
requestedPharmacy: "Pharmacy ABC",
idDocument: null, // use null to remove the existing file
selfie: null,
back: null,
heightFeet: "5",
heightInches: "8",
historyFastHeartbeat: false,
notes: "Updated notes",
status: "Approved",
thyroidCancer: false,
recentBariatricSurgery: false,
chronicConditions: false,
type1: false,
cancer: false,
mens2: false,
glp1Reaction: false
};
const updatedRecord = await pb.collection('telepath_api')
.update('RECORD_ID', updateData);
Note: If partial updates are not allowed, always include all required fields.
8. Deleting a Record (DELETE)
Endpoint:
DELETE /api/collections/telepath_api/records/:id
Replace :id with the record's ID. Requires admin token:
await pb.collection('telepath_api').delete('RECORD_ID');
9. Realtime Subscriptions (SSE)
Endpoint:
SSE /api/realtime
Subscribe to create, update, and delete events in realtime.
Examples (JavaScript SDK):
// Subscribe to ALL telepath_api record events
pb.collection('telepath_api').subscribe('*', function (e) {
console.log(e.action); // create, update, delete
console.log(e.record);
});
// Subscribe to a SINGLE record
pb.collection('telepath_api').subscribe('RECORD_ID', function (e) {
console.log(e.record);
});
// Unsubscribe
pb.collection('telepath_api').unsubscribe('RECORD_ID'); // unsub record
pb.collection('telepath_api').unsubscribe('*'); // unsub all in telepath_api
pb.collection('telepath_api').unsubscribe(); // unsub everything in telepath_api
Event Format:
{
"action": "create", // or "update" or "delete"
"record": {
"id": "RECORD_ID",
"collectionId": "opw8b6r2q5625v9",
"collectionName": "telepath_api",
"created": "2022-01-01T01:00:00.123Z",
"updated": "2022-01-01T23:59:59.456Z",
"firstName": "test",
"lastName": "test",
"email": "test@example.com",
"phoneNumber": "test",
"tos": true,
"dob": "2022-01-01T10:00:00.123Z",
"gender": "test",
"weight": 123,
"address": "test",
"city": "test",
"state": "test",
"zip": 123,
"country": "test",
"preName": "test",
"refCode": "test",
"preg": true,
"glp1": true,
"WeightLossGoals": "test",
"allergies": "test",
"medicalConditions": "test",
"medications": "test",
"requestedProductName": "test",
"requestedPharmacy": "test",
"idDocument": ["filename.jpg"],
"selfie": ["filename.jpg"],
"heightFeet": "3",
"heightInches": "0",
"historyFastHeartbeat": true,
"notes": "test",
"back": ["filename.jpg"],
"status": "Pending",
"thyroidCancer": true,
"recentBariatricSurgery": true,
"chronicConditions": true,
"type1": true,
"cancer": true,
"mens2": true,
"glp1Reaction": true
}
}