The CRM Companies API manages company records in the CRM system.
Edge Function: crm-companies-api
Base URL: https://bgbavxtjlbvgplozizxu.supabase.co/functions/v1/crm-companies-api
All requests require authentication via Supabase Auth:
Authorization: Bearer <supabase_access_token>
Create a new company record.
Method: POST
Path: /
Request:
{
name: string, // Required
website?: string,
industry?: string,
employee_count?: number,
annual_revenue?: number,
email?: string,
phone?: string,
address?: string,
city?: string,
state?: string,
postal_code?: string,
country?: string,
linkedin?: string,
twitter?: string,
facebook?: string,
description?: string,
notes?: string
}
Response:
{
data: {
id: string,
name: string,
website: string | null,
industry: string | null,
employee_count: number | null,
annual_revenue: number | null,
email: string | null,
phone: string | null,
address: string | null,
city: string | null,
state: string | null,
postal_code: string | null,
country: string | null,
linkedin: string | null,
twitter: string | null,
facebook: string | null,
description: string | null,
notes: string | null,
created_by: string,
created_at: string,
updated_at: string
}
}
Example:
const response = await fetch(`${API_BASE}/crm-companies-api`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${session.access_token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Acme Corporation',
website: 'https://acme.com',
industry: 'Technology',
employee_count: 500,
email: 'contact@acme.com',
country: 'USA'
})
});
Get a paginated list of companies with optional search.
Method: GET
Path: /
Query Parameters:
limit (optional): Number of records to return (default: 50)offset (optional): Number of records to skip (default: 0)search (optional): Search term (searches name, email, website)Response:
{
data: Company[],
count: number
}
Example:
// List all companies
const response = await fetch(
`${API_BASE}/crm-companies-api?limit=20&offset=0`,
{
headers: {
'Authorization': `Bearer ${session.access_token}`
}
}
);
// Search companies
const searchResponse = await fetch(
`${API_BASE}/crm-companies-api?search=acme`,
{
headers: {
'Authorization': `Bearer ${session.access_token}`
}
}
);
Get a specific company by ID with associated contacts.
Method: GET
Path: /{companyId}
Response:
{
data: {
id: string,
name: string,
// ... all company fields
crm_company_contacts: Array<{
id: string,
contact_id: string,
role: string,
is_primary: boolean,
created_at: string
}>
}
}
Update an existing company.
Method: PATCH
Path: /{companyId}
Request:
{
name?: string,
website?: string,
industry?: string,
employee_count?: number,
annual_revenue?: number,
// ... any other company fields
}
Response:
{
data: Company // Updated company
}
Delete a company.
Method: DELETE
Path: /{companyId}
Response:
{
message: 'Company deleted successfully'
}
Associate a contact with a company.
Method: POST
Path: /{companyId}/contacts
Request:
{
contactId: string,
role?: string, // e.g., 'CEO', 'Manager', 'Sales Rep'
isPrimary?: boolean // Mark as primary contact
}
Response:
{
data: {
id: string,
company_id: string,
contact_id: string,
role: string,
is_primary: boolean,
created_at: string
}
}
Remove a contact-company association.
Method: DELETE
Path: /{companyId}/contacts/{contactId}
Response:
{
message: 'Contact unlinked from company successfully'
}
All errors return a standard format:
{
error: string // Error message
}
Common Error Codes:
401 - Unauthorized (missing or invalid token)404 - Company not found400 - Bad request (validation error, e.g., missing company name)500 - Internal server error