Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor site management API to use organization ID in endpoints

Bill Yang1aa65143b50d
diff --git a/client/src/api/admin/endpoints/sites.ts b/client/src/api/admin/endpoints/sites.ts
index 5e7bf6276..d009a1030 100644
--- a/client/src/api/admin/endpoints/sites.ts
+++ b/client/src/api/admin/endpoints/sites.ts
@@ -75,7 +75,7 @@ export function addSite(
blockBots?: boolean;
}
) {
- return authedFetch<{ siteId: number }>(`/sites/${organizationId}`, undefined, {
+ return authedFetch<{ siteId: number }>(`/organizations/${organizationId}/sites`, undefined, {
method: "POST",
data: {
domain,
diff --git a/client/src/app/[site]/api-playground/utils/endpointConfig.ts b/client/src/app/[site]/api-playground/utils/endpointConfig.ts
index d6236e440..c9362621d 100644
--- a/client/src/app/[site]/api-playground/utils/endpointConfig.ts
+++ b/client/src/app/[site]/api-playground/utils/endpointConfig.ts
@@ -361,21 +361,6 @@ export const endpointCategories: EndpointCategory[] = [
{
name: "Sites",
endpoints: [
- {
- method: "POST",
- path: "/sites/:orgId",
- name: "Create Site",
- description: "Creates a new site in an organization. Requires admin/owner role.",
- hasCommonParams: false,
- pathParams: ["orgId"],
- hasRequestBody: true,
- requestBodyExample: {
- domain: "example.com",
- name: "My Website",
- public: false,
- blockBots: true,
- },
- },
{
method: "GET",
path: "/sites/:site",
@@ -437,6 +422,55 @@ export const endpointCategories: EndpointCategory[] = [
},
],
},
+ {
+ name: "Organizations",
+ endpoints: [
+ {
+ method: "GET",
+ path: "/organizations/:organizationId/sites",
+ name: "Get Organization Sites",
+ description: "Returns all sites within an organization with session counts and subscription info",
+ hasCommonParams: false,
+ pathParams: ["organizationId"],
+ },
+ {
+ method: "POST",
+ path: "/organizations/:organizationId/sites",
+ name: "Create Site",
+ description: "Creates a new site in an organization. Requires admin/owner role.",
+ hasCommonParams: false,
+ pathParams: ["organizationId"],
+ hasRequestBody: true,
+ requestBodyExample: {
+ domain: "example.com",
+ name: "My Website",
+ public: false,
+ blockBots: true,
+ },
+ },
+ {
+ method: "GET",
+ path: "/organizations/:organizationId/members",
+ name: "Get Organization Members",
+ description: "Returns all members of an organization with user details",
+ hasCommonParams: false,
+ pathParams: ["organizationId"],
+ },
+ {
+ method: "POST",
+ path: "/organizations/:organizationId/members",
+ name: "Add Organization Member",
+ description: "Adds a user to an organization with a specified role",
+ hasCommonParams: false,
+ pathParams: ["organizationId"],
+ hasRequestBody: true,
+ requestBodyExample: {
+ email: "[email protected]",
+ role: "member",
+ },
+ },
+ ],
+ },
];
// Flatten all endpoints for easy lookup
@@ -527,12 +561,19 @@ export const parameterMetadata: Record<
userId: { label: "User ID", type: "text", placeholder: "User ID" },
stepNumber: { label: "Step Number", type: "number", placeholder: "Step number (1-indexed)" },
siteId: { label: "Site ID", type: "number", placeholder: "Site ID" },
+ organizationId: { label: "Organization ID", type: "text", placeholder: "org_abc123" },
// Sites-specific params
action: {
label: "Action",
type: "select",
options: ["generate_private_link_key", "revoke_private_link_key"],
},
+ // Organizations-specific params
+ role: {
+ label: "Role",
+ type: "select",
+ options: ["admin", "member", "owner"],
+ },
};
// Method colors for UI
diff --git a/docs/content/docs/api/meta.json b/docs/content/docs/api/meta.json
index dd6f8da30..563a5d4e1 100644
--- a/docs/content/docs/api/meta.json
+++ b/docs/content/docs/api/meta.json
@@ -1,4 +1,4 @@
{
"title": "API",
- "pages": ["getting-started", "sending-events", "stats", "sites"]
+ "pages": ["getting-started", "sending-events", "stats", "organizations", "sites"]
}
diff --git a/docs/content/docs/api/organizations.mdx b/docs/content/docs/api/organizations.mdx
new file mode 100644
index 000000000..ebf3fb05e
--- /dev/null
+++ b/docs/content/docs/api/organizations.mdx
@@ -0,0 +1,1124 @@
+---
+title: Organizations
+description: Manage organizations, sites, and members
+full: true
+---
+
+import { TypeTable } from 'fumadocs-ui/components/type-table';
+import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
+
+See the [API Reference](/docs/api/getting-started) for authentication details.
+
+## Endpoints
+
+<div className="flex flex-col gap-2 my-6">
+ <a href="#get-organization-sites" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">
+ <span className="px-2 py-1 text-xs font-bold rounded bg-green-500/20 text-green-600 dark:text-green-400">GET</span>
+ <code className="text-sm">/api/organizations/:organizationId/sites</code>
+ </a>
+ <a href="#create-site" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">
+ <span className="px-2 py-1 text-xs font-bold rounded bg-blue-500/20 text-blue-600 dark:text-blue-400">POST</span>
+ <code className="text-sm">/api/organizations/:organizationId/sites</code>
+ </a>
+ <a href="#get-organization-members" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">
+ <span className="px-2 py-1 text-xs font-bold rounded bg-green-500/20 text-green-600 dark:text-green-400">GET</span>
+ <code className="text-sm">/api/organizations/:organizationId/members</code>
+ </a>
+ <a href="#add-organization-member" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">
+ <span className="px-2 py-1 text-xs font-bold rounded bg-blue-500/20 text-blue-600 dark:text-blue-400">POST</span>
+ <code className="text-sm">/api/organizations/:organizationId/members</code>
+ </a>
+</div>
+
+---
+
+## Get Organization Sites
+
+<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
+<div>
+
+```
+GET /api/organizations/:organizationId/sites
+```
+
+Returns all sites within an organization along with session counts from the last 24 hours and subscription information. Requires membership in the organization.
+
+### Path Parameters
+
+<TypeTable
+ type={{
+ organizationId: {
+ description: 'Organization ID',
+ type: 'string',
+ required: true,
+ },
+ }}
+/>
+
+### Response
+
+<TypeTable
+ type={{
+ organization: {
+ description: 'Organization details',
+ type: 'object | null',
+ },
+ sites: {
+ description: 'Array of sites in the organization',
+ type: 'array',
+ },
+ subscription: {
+ description: 'Subscription and usage information',
+ type: 'object',
+ },
+ }}
+/>
+
+#### Site Object
+
+Each site in the `sites` array contains:
+
+<TypeTable
+ type={{
+ siteId: {
+ description: 'Numeric site ID',
+ type: 'number',
+ },
+ id: {
+ description: 'Site UUID',
+ type: 'string',
+ },
+ domain: {
+ description: 'Site domain',
+ type: 'string',
+ },
+ name: {
+ description: 'Site name',
+ type: 'string',
+ },
+ organizationId: {
+ description: 'Organization ID',
+ type: 'string',
+ },
+ createdBy: {
+ description: 'User ID who created the site',
+ type: 'string',
+ },
+ public: {
+ description: 'Whether analytics are publicly accessible',
+ type: 'boolean',
+ },
+ saltUserIds: {
+ description: 'Whether user IDs are salted',
+ type: 'boolean',
+ },
+ blockBots: {
+ description: 'Whether bot traffic is blocked',
+ type: 'boolean',
+ },
+ sessionsLast24Hours: {
+ description: 'Number of unique sessions in the last 24 hours',
+ type: 'number',
+ },
+ isOwner: {
+ description: 'Whether the current user has admin/owner role',
+ type: 'boolean',
+ },
+ }}
+/>
+
+#### Subscription Object
+
+<TypeTable
+ type={{
+ monthlyEventCount: {
+ description: 'Total events used this month',
+ type: 'number',
+ },
+ eventLimit: {
+ description: 'Monthly event limit for the subscription',
+ type: 'number',
+ },
+ overMonthlyLimit: {
+ description: 'Whether the event limit has been exceeded',
+ type: 'boolean',
+ },
+ planName: {
+ description: 'Subscription plan name',
+ type: 'string',
+ },
+ status: {
+ description: 'Subscription status',
+ type: 'string',
+ },
+ isPro: {
+ description: 'Whether this is a pro plan',
+ type: 'boolean',
+ },
+ }}
+/>
+
+</div>
+<div className="flex flex-col gap-4">
+
+<Tabs items={['cURL', 'JavaScript', 'Python', 'PHP', 'Ruby', 'Go', 'Rust', 'Java', '.NET']}>
+ <Tab value="cURL">
+```bash title="Request"
+curl -X GET "https://api.rybbit.io/api/organizations/org_123/sites" \
+ -H "Authorization: Bearer your_api_key_here"
+```
+ </Tab>
+ <Tab value="JavaScript">
+```javascript title="Request"
+const organizationId = 'org_123';
+const response = await fetch(
+ `https://api.rybbit.io/api/organizations/${organizationId}/sites`,
+ {
+ headers: {
+ 'Authorization': 'Bearer your_api_key_here'
+ }
+ }
+);
+
+const data = await response.json();
+```
+ </Tab>
+ <Tab value="Python">
+```python title="Request"
+import requests
+
+organization_id = 'org_123'
+response = requests.get(
+ f'https://api.rybbit.io/api/organizations/{organization_id}/sites',
+ headers={
+ 'Authorization': 'Bearer your_api_key_here'
+ }
+)
+
+data = response.json()
+```
+ </Tab>
+ <Tab value="PHP">
+```php title="Request"
+$organizationId = 'org_123';
+$ch = curl_init();
+curl_setopt($ch, CURLOPT_URL, "https://api.rybbit.io/api/organizations/{$organizationId}/sites");
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ 'Authorization: Bearer your_api_key_here'
+]);
+
+$response = curl_exec($ch);
+curl_close($ch);
+
+$data = json_decode($response, true);
+```
+ </Tab>
+ <Tab value="Ruby">
+```ruby title="Request"
+require 'net/http'
+require 'json'
+
+organization_id = 'org_123'
+uri = URI("https://api.rybbit.io/api/organizations/#{organization_id}/sites")
+req = Net::HTTP::Get.new(uri)
+req['Authorization'] = 'Bearer your_api_key_here'
+
+res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
+data = JSON.parse(res.body)
+```
+ </Tab>
+ <Tab value="Go">
+```go title="Request"
+organizationId := "org_123"
+req, _ := http.NewRequest("GET", "https://api.rybbit.io/api/organizations/"+organizationId+"/sites", nil)
+req.Header.Set("Authorization", "Bearer your_api_key_here")
+
+client := &http.Client{}
+resp, _ := client.Do(req)
+defer resp.Body.Close()
+
+var data map[string]interface{}
+json.NewDecoder(resp.Body).Decode(&data)
+```
+ </Tab>
+ <Tab value="Rust">
+```rust title="Request"
+let organization_id = "org_123";
+let client = reqwest::Client::new();
+let res = client
+ .get(format!("https://api.rybbit.io/api/organizations/{}/sites", organization_id))
+ .header("Authorization", "Bearer your_api_key_here")
+ .send()
+ .await?;
+
+let data: serde_json::Value = res.json().await?;
+```
+ </Tab>
+ <Tab value="Java">
+```java title="Request"
+String organizationId = "org_123";
+HttpClient client = HttpClient.newHttpClient();
+HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("https://api.rybbit.io/api/organizations/" + organizationId + "/sites"))
+ .header("Authorization", "Bearer your_api_key_here")
+ .GET()
+ .build();
+
+HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
+```
+ </Tab>
+ <Tab value=".NET">
+```csharp title="Request"
+var organizationId = "org_123";
+using var client = new HttpClient();
+client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_key_here");
+
+var response = await client.GetAsync($"https://api.rybbit.io/api/organizations/{organizationId}/sites");
+var data = await response.Content.ReadAsStringAsync();
+```
+ </Tab>
+</Tabs>
+
+```json title="Response"
+{
+ "organization": {
+ "id": "org_123",
+ "name": "Acme Inc"
+ },
+ "sites": [
+ {
+ "siteId": 456,
+ "id": "site_abc123",
+ "domain": "example.com",
+ "name": "My Website",
+ "organizationId": "org_123",
+ "createdBy": "user_xyz789",
+ "public": false,
+ "saltUserIds": false,
+ "blockBots": true,
+ "sessionsLast24Hours": 1247,
+ "isOwner": true
+ }
+ ],
+ "subscription": {
+ "monthlyEventCount": 45230,
+ "eventLimit": 100000,
+ "overMonthlyLimit": false,
+ "planName": "pro",
+ "status": "active",
+ "isPro": true
+ }
+}
+```
+
+</div>
+</div>
+
+---
+
+## Create Site
+
+<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
+<div>
+
+```
+POST /api/organizations/:organizationId/sites
+```
+
+Creates a new site within an organization. Requires admin or owner role in the organization.
+
+### Path Parameters
+
+<TypeTable
+ type={{
+ organizationId: {
+ description: 'Organization ID to add the site to',
+ type: 'string',
+ required: true,
+ },
+ }}
+/>
+
+### Request Body
+
+<TypeTable
+ type={{
+ domain: {
+ description: 'Site domain',
+ type: 'string',
+ typeDescription: 'Valid domain format (e.g., example.com)',
+ required: true,
+ },
+ name: {
+ description: 'Site display name',
+ type: 'string',
+ required: true,
+ },
+ public: {
+ description: 'Make analytics publicly accessible',
+ type: 'boolean',
+ default: false,
+ },
+ saltUserIds: {
+ description: 'Salt user IDs for privacy',
+ type: 'boolean',
+ default: false,
+ },
+ blockBots: {
+ description: 'Block bot traffic',
+ type: 'boolean',
+ default: true,
+ },
+ }}
+/>
+
+### Response
+
+Returns the created site object with the assigned `siteId`.
+
+<TypeTable
+ type={{
+ siteId: {
+ description: 'Numeric site ID (auto-assigned)',
+ type: 'number',
+ },
+ id: {
+ description: 'Site UUID',
+ type: 'string',
+ },
+ domain: {
+ description: 'Site domain',
+ type: 'string',
+ },
+ name: {
+ description: 'Site name',
+ type: 'string',
+ },
+ organizationId: {
+ description: 'Organization ID',
+ type: 'string',
+ },
+ createdBy: {
+ description: 'User ID who created the site',
+ type: 'string',
+ },
+ public: {
+ description: 'Whether analytics are public',
+ type: 'boolean',
+ },
+ saltUserIds: {
+ description: 'Whether user IDs are salted',
+ type: 'boolean',
+ },
+ blockBots: {
+ description: 'Whether bot traffic is blocked',
+ type: 'boolean',
+ },
+ }}
+/>
+
+</div>
+<div className="flex flex-col gap-4">
+
+<Tabs items={['cURL', 'JavaScript', 'Python', 'PHP', 'Ruby', 'Go', 'Rust', 'Java', '.NET']}>
+ <Tab value="cURL">
+```bash title="Request"
+curl -X POST "https://api.rybbit.io/api/organizations/org_123/sites" \
+ -H "Authorization: Bearer your_api_key_here" \
+ -H "Content-Type: application/json" \
+ -d '{"domain": "example.com", "name": "My Website", "blockBots": true}'
+```
+ </Tab>
+ <Tab value="JavaScript">
+```javascript title="Request"
+const organizationId = 'org_123';
+const response = await fetch(
+ `https://api.rybbit.io/api/organizations/${organizationId}/sites`,
+ {
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer your_api_key_here',
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ domain: 'example.com',
+ name: 'My Website',
+ blockBots: true
+ })
+ }
+);
+
+const data = await response.json();
+```
+ </Tab>
+ <Tab value="Python">
+```python title="Request"
+import requests
+
+organization_id = 'org_123'
+response = requests.post(
+ f'https://api.rybbit.io/api/organizations/{organization_id}/sites',
+ json={
+ 'domain': 'example.com',
+ 'name': 'My Website',
+ 'blockBots': True
+ },
+ headers={
+ 'Authorization': 'Bearer your_api_key_here'
+ }
+)
+
+data = response.json()
+```
+ </Tab>
+ <Tab value="PHP">
+```php title="Request"
+$organizationId = 'org_123';
+$ch = curl_init();
+curl_setopt($ch, CURLOPT_URL, "https://api.rybbit.io/api/organizations/{$organizationId}/sites");
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($ch, CURLOPT_POST, true);
+curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
+ 'domain' => 'example.com',
+ 'name' => 'My Website',
+ 'blockBots' => true
+]));
+curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ 'Authorization: Bearer your_api_key_here',
+ 'Content-Type: application/json'
+]);
+
+$response = curl_exec($ch);
+curl_close($ch);
+
+$data = json_decode($response, true);
+```
+ </Tab>
+ <Tab value="Ruby">
+```ruby title="Request"
+require 'net/http'
+require 'json'
+
+organization_id = 'org_123'
+uri = URI("https://api.rybbit.io/api/organizations/#{organization_id}/sites")
+req = Net::HTTP::Post.new(uri)
+req['Authorization'] = 'Bearer your_api_key_here'
+req['Content-Type'] = 'application/json'
+req.body = {
+ domain: 'example.com',
+ name: 'My Website',
+ blockBots: true
+}.to_json
+
+res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
+data = JSON.parse(res.body)
+```
+ </Tab>
+ <Tab value="Go">
+```go title="Request"
+organizationId := "org_123"
+body := bytes.NewBuffer([]byte(`{
+ "domain": "example.com",
+ "name": "My Website",
+ "blockBots": true
+}`))
+req, _ := http.NewRequest("POST", "https://api.rybbit.io/api/organizations/"+organizationId+"/sites", body)
+req.Header.Set("Authorization", "Bearer your_api_key_here")
+req.Header.Set("Content-Type", "application/json")
+
+client := &http.Client{}
+resp, _ := client.Do(req)
+defer resp.Body.Close()
+
+var data map[string]interface{}
+json.NewDecoder(resp.Body).Decode(&data)
+```
+ </Tab>
+ <Tab value="Rust">
+```rust title="Request"
+let organization_id = "org_123";
+let client = reqwest::Client::new();
+let res = client
+ .post(format!("https://api.rybbit.io/api/organizations/{}/sites", organization_id))
+ .header("Authorization", "Bearer your_api_key_here")
+ .json(&serde_json::json!({
+ "domain": "example.com",
+ "name": "My Website",
+ "blockBots": true
+ }))
+ .send()
+ .await?;
+
+let data: serde_json::Value = res.json().await?;
+```
+ </Tab>
+ <Tab value="Java">
+```java title="Request"
+String organizationId = "org_123";
+HttpClient client = HttpClient.newHttpClient();
+String json = "{\"domain\": \"example.com\", \"name\": \"My Website\", \"blockBots\": true}";
+HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("https://api.rybbit.io/api/organizations/" + organizationId + "/sites"))
+ .header("Authorization", "Bearer your_api_key_here")
+ .header("Content-Type", "application/json")
+ .POST(HttpRequest.BodyPublishers.ofString(json))
+ .build();
+
+HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
+```
+ </Tab>
+ <Tab value=".NET">
+```csharp title="Request"
+var organizationId = "org_123";
+using var client = new HttpClient();
+client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_key_here");
+
+var content = new StringContent(
+ "{\"domain\": \"example.com\", \"name\": \"My Website\", \"blockBots\": true}",
+ Encoding.UTF8,
+ "application/json"
+);
+
+var response = await client.PostAsync($"https://api.rybbit.io/api/organizations/{organizationId}/sites", content);
+var data = await response.Content.ReadAsStringAsync();
+```
+ </Tab>
+</Tabs>
+
+```json title="Response"
+{
+ "siteId": 456,
+ "id": "a1b2c3d4e5f6",
+ "domain": "example.com",
+ "name": "My Website",
+ "organizationId": "org_123",
+ "createdBy": "user_xyz789",
+ "public": false,
+ "saltUserIds": false,
+ "blockBots": true
+}
+```
+
+</div>
+</div>
+
+---
+
+## Get Organization Members
+
+<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
+<div>
+
+```
+GET /api/organizations/:organizationId/members
+```
+
+Returns all members of an organization with their user details and roles. Requires membership in the organization.
+
+### Path Parameters
+
+<TypeTable
+ type={{
+ organizationId: {
+ description: 'Organization ID',
+ type: 'string',
+ required: true,
+ },
+ }}
+/>
+
+### Response
+
+<TypeTable
+ type={{
+ success: {
+ description: 'Whether the request was successful',
+ type: 'boolean',
+ },
+ data: {
+ description: 'Array of organization members',
+ type: 'array',
+ },
+ }}
+/>
+
+#### Member Object
+
+Each member in the `data` array contains:
+
+<TypeTable
+ type={{
+ id: {
+ description: 'Member record ID',
+ type: 'string',
+ },
+ role: {
+ description: 'Member role in the organization',
+ type: 'string',
+ typeDescription: '"owner" | "admin" | "member"',
+ },
+ userId: {
+ description: 'User ID',
+ type: 'string',
+ },
+ organizationId: {
+ description: 'Organization ID',
+ type: 'string',
+ },
+ createdAt: {
+ description: 'Timestamp when member was added',
+ type: 'string',
+ typeDescription: 'ISO 8601 datetime',
+ },
+ user: {
+ description: 'User details',
+ type: 'object',
+ },
+ }}
+/>
+
+#### User Object
+
+<TypeTable
+ type={{
+ id: {
+ description: 'User ID',
+ type: 'string',
+ },
+ name: {
+ description: 'User display name',
+ type: 'string',
+ },
+ email: {
+ description: 'User email address',
+ type: 'string',
+ },
+ }}
+/>
+
+</div>
+<div className="flex flex-col gap-4">
+
+<Tabs items={['cURL', 'JavaScript', 'Python', 'PHP', 'Ruby', 'Go', 'Rust', 'Java', '.NET']}>
+ <Tab value="cURL">
+```bash title="Request"
+curl -X GET "https://api.rybbit.io/api/organizations/org_123/members" \
+ -H "Authorization: Bearer your_api_key_here"
+```
+ </Tab>
+ <Tab value="JavaScript">
+```javascript title="Request"
+const organizationId = 'org_123';
+const response = await fetch(
+ `https://api.rybbit.io/api/organizations/${organizationId}/members`,
+ {
+ headers: {
+ 'Authorization': 'Bearer your_api_key_here'
+ }
+ }
+);
+
+const data = await response.json();
+```
+ </Tab>
+ <Tab value="Python">
+```python title="Request"
+import requests
+
+organization_id = 'org_123'
+response = requests.get(
+ f'https://api.rybbit.io/api/organizations/{organization_id}/members',
+ headers={
+ 'Authorization': 'Bearer your_api_key_here'
+ }
+)
+
+data = response.json()
+```
+ </Tab>
+ <Tab value="PHP">
+```php title="Request"
+$organizationId = 'org_123';
+$ch = curl_init();
+curl_setopt($ch, CURLOPT_URL, "https://api.rybbit.io/api/organizations/{$organizationId}/members");
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ 'Authorization: Bearer your_api_key_here'
+]);
+
+$response = curl_exec($ch);
+curl_close($ch);
+
+$data = json_decode($response, true);
+```
+ </Tab>
+ <Tab value="Ruby">
+```ruby title="Request"
+require 'net/http'
+require 'json'
+
+organization_id = 'org_123'
+uri = URI("https://api.rybbit.io/api/organizations/#{organization_id}/members")
+req = Net::HTTP::Get.new(uri)
+req['Authorization'] = 'Bearer your_api_key_here'
+
+res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
+data = JSON.parse(res.body)
+```
+ </Tab>
+ <Tab value="Go">
+```go title="Request"
+organizationId := "org_123"
+req, _ := http.NewRequest("GET", "https://api.rybbit.io/api/organizations/"+organizationId+"/members", nil)
+req.Header.Set("Authorization", "Bearer your_api_key_here")
+
+client := &http.Client{}
+resp, _ := client.Do(req)
+defer resp.Body.Close()
+
+var data map[string]interface{}
+json.NewDecoder(resp.Body).Decode(&data)
+```
+ </Tab>
+ <Tab value="Rust">
+```rust title="Request"
+let organization_id = "org_123";
+let client = reqwest::Client::new();
+let res = client
+ .get(format!("https://api.rybbit.io/api/organizations/{}/members", organization_id))
+ .header("Authorization", "Bearer your_api_key_here")
+ .send()
+ .await?;
+
+let data: serde_json::Value = res.json().await?;
+```
+ </Tab>
+ <Tab value="Java">
+```java title="Request"
+String organizationId = "org_123";
+HttpClient client = HttpClient.newHttpClient();
+HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("https://api.rybbit.io/api/organizations/" + organizationId + "/members"))
+ .header("Authorization", "Bearer your_api_key_here")
+ .GET()
+ .build();
+
+HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
+```
+ </Tab>
+ <Tab value=".NET">
+```csharp title="Request"
+var organizationId = "org_123";
+using var client = new HttpClient();
+client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_key_here");
+
+var response = await client.GetAsync($"https://api.rybbit.io/api/organizations/{organizationId}/members");
+var data = await response.Content.ReadAsStringAsync();
+```
+ </Tab>
+</Tabs>
+
+```json title="Response"
+{
+ "success": true,
+ "data": [
+ {
+ "id": "member_abc123",
+ "role": "owner",
+ "userId": "user_xyz789",
+ "organizationId": "org_123",
+ "createdAt": "2024-01-15T10:30:00.000Z",
+ "user": {
+ "id": "user_xyz789",
+ "name": "John Doe",
+ "email": "[email protected]"
+ }
+ },
+ {
+ "id": "member_def456",
+ "role": "member",
+ "userId": "user_abc456",
+ "organizationId": "org_123",
+ "createdAt": "2024-02-20T14:15:00.000Z",
+ "user": {
+ "id": "user_abc456",
+ "name": "Jane Smith",
+ "email": "[email protected]"
+ }
+ }
+ ]
+}
+```
+
+</div>
+</div>
+
+---
+
+## Add Organization Member
+
+<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
+<div>
+
+```
+POST /api/organizations/:organizationId/members
+```
+
+Adds a user to an organization with a specified role. The user must already exist in the system. Requires admin or owner role in the organization.
+
+### Path Parameters
+
+<TypeTable
+ type={{
+ organizationId: {
+ description: 'Organization ID',
+ type: 'string',
+ required: true,
+ },
+ }}
+/>
+
+### Request Body
+
+<TypeTable
+ type={{
+ email: {
+ description: 'Email address of the user to add',
+ type: 'string',
+ typeDescription: 'Must match an existing user',
+ required: true,
+ },
+ role: {
+ description: 'Role to assign to the user',
+ type: 'string',
+ typeDescription: '"admin" | "member" | "owner"',
+ required: true,
+ },
+ }}
+/>
+
+### Response
+
+Returns a success message when the user is added successfully.
+
+<TypeTable
+ type={{
+ message: {
+ description: 'Success message',
+ type: 'string',
+ },
+ }}
+/>
+
+### Error Responses
+
+<TypeTable
+ type={{
+ '400': {
+ description: 'Invalid input (missing fields, invalid role, or user already a member)',
+ type: 'object',
+ },
+ '401': {
+ description: 'Unauthorized (not an admin/owner of the organization)',
+ type: 'object',
+ },
+ '404': {
+ description: 'User not found',
+ type: 'object',
+ },
+ '500': {
+ description: 'Internal server error',
+ type: 'object',
+ },
+ }}
+/>
+
+</div>
+<div className="flex flex-col gap-4">
+
+<Tabs items={['cURL', 'JavaScript', 'Python', 'PHP', 'Ruby', 'Go', 'Rust', 'Java', '.NET']}>
+ <Tab value="cURL">
+```bash title="Request"
+curl -X POST "https://api.rybbit.io/api/organizations/org_123/members" \
+ -H "Authorization: Bearer your_api_key_here" \
+ -H "Content-Type: application/json" \
+ -d '{"email": "[email protected]", "role": "member"}'
+```
+ </Tab>
+ <Tab value="JavaScript">
+```javascript title="Request"
+const organizationId = 'org_123';
+const response = await fetch(
+ `https://api.rybbit.io/api/organizations/${organizationId}/members`,
+ {
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer your_api_key_here',
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ email: '[email protected]',
+ role: 'member'
+ })
+ }
+);
+
+const data = await response.json();
+```
+ </Tab>
+ <Tab value="Python">
+```python title="Request"
+import requests
+
+organization_id = 'org_123'
+response = requests.post(
+ f'https://api.rybbit.io/api/organizations/{organization_id}/members',
+ json={
+ 'email': '[email protected]',
+ 'role': 'member'
+ },
+ headers={
+ 'Authorization': 'Bearer your_api_key_here'
+ }
+)
+
+data = response.json()
+```
+ </Tab>
+ <Tab value="PHP">
+```php title="Request"
+$organizationId = 'org_123';
+$ch = curl_init();
+curl_setopt($ch, CURLOPT_URL, "https://api.rybbit.io/api/organizations/{$organizationId}/members");
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($ch, CURLOPT_POST, true);
+curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
+ 'email' => '[email protected]',
+ 'role' => 'member'
+]));
+curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ 'Authorization: Bearer your_api_key_here',
+ 'Content-Type: application/json'
+]);
+
+$response = curl_exec($ch);
+curl_close($ch);
+
+$data = json_decode($response, true);
+```
+ </Tab>
+ <Tab value="Ruby">
+```ruby title="Request"
+require 'net/http'
+require 'json'
+
+organization_id = 'org_123'
+uri = URI("https://api.rybbit.io/api/organizations/#{organization_id}/members")
+req = Net::HTTP::Post.new(uri)
+req['Authorization'] = 'Bearer your_api_key_here'
+req['Content-Type'] = 'application/json'
+req.body = {
+ email: '[email protected]',
+ role: 'member'
+}.to_json
+
+res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
+data = JSON.parse(res.body)
+```
+ </Tab>
+ <Tab value="Go">
+```go title="Request"
+organizationId := "org_123"
+body := bytes.NewBuffer([]byte(`{
+ "email": "[email protected]",
+ "role": "member"
+}`))
+req, _ := http.NewRequest("POST", "https://api.rybbit.io/api/organizations/"+organizationId+"/members", body)
+req.Header.Set("Authorization", "Bearer your_api_key_here")
+req.Header.Set("Content-Type", "application/json")
+
+client := &http.Client{}
+resp, _ := client.Do(req)
+defer resp.Body.Close()
+
+var data map[string]interface{}
+json.NewDecoder(resp.Body).Decode(&data)
+```
+ </Tab>
+ <Tab value="Rust">
+```rust title="Request"
+let organization_id = "org_123";
+let client = reqwest::Client::new();
+let res = client
+ .post(format!("https://api.rybbit.io/api/organizations/{}/members", organization_id))
+ .header("Authorization", "Bearer your_api_key_here")
+ .json(&serde_json::json!({
+ "email": "[email protected]",
+ "role": "member"
+ }))
+ .send()
+ .await?;
+
+let data: serde_json::Value = res.json().await?;
+```
+ </Tab>
+ <Tab value="Java">
+```java title="Request"
+String organizationId = "org_123";
+HttpClient client = HttpClient.newHttpClient();
+String json = "{\"email\": \"[email protected]\", \"role\": \"member\"}";
+HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("https://api.rybbit.io/api/organizations/" + organizationId + "/members"))
+ .header("Authorization", "Bearer your_api_key_here")
+ .header("Content-Type", "application/json")
+ .POST(HttpRequest.BodyPublishers.ofString(json))
+ .build();
+
+HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
+```
+ </Tab>
+ <Tab value=".NET">
+```csharp title="Request"
+var organizationId = "org_123";
+using var client = new HttpClient();
+client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_key_here");
+
+var content = new StringContent(
+ "{\"email\": \"[email protected]\", \"role\": \"member\"}",
+ Encoding.UTF8,
+ "application/json"
+);
+
+var response = await client.PostAsync($"https://api.rybbit.io/api/organizations/{organizationId}/members", content);
+var data = await response.Content.ReadAsStringAsync();
+```
+ </Tab>
+</Tabs>
+
+```json title="Response"
+{
+ "message": "User added to organization successfully"
+}
+```
+
+```json title="Error Response (400 - Already a Member)"
+{
+ "error": "User is already a member of this organization"
+}
+```
+
+```json title="Error Response (404 - User Not Found)"
+{
+ "error": "User not found"
+}
+```
+
+```json title="Error Response (401 - Unauthorized)"
+{
+ "error": "Unauthorized"
+}
+```
+
+</div>
+</div>
diff --git a/docs/content/docs/api/sites.mdx b/docs/content/docs/api/sites.mdx
index bb2b27d58..6821634f7 100644
--- a/docs/content/docs/api/sites.mdx
+++ b/docs/content/docs/api/sites.mdx
@@ -12,10 +12,6 @@ See the [API Reference](/docs/api/getting-started) for authentication details.
## Endpoints
<div className="flex flex-col gap-2 my-6">
- <a href="#create-site" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">
- <span className="px-2 py-1 text-xs font-bold rounded bg-blue-500/20 text-blue-600 dark:text-blue-400">POST</span>
- <code className="text-sm">/api/sites/:orgId</code>
- </a>
<a href="#get-site" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">
<span className="px-2 py-1 text-xs font-bold rounded bg-green-500/20 text-green-600 dark:text-green-400">GET</span>
<code className="text-sm">/api/sites/:siteId</code>
@@ -48,294 +44,6 @@ See the [API Reference](/docs/api/getting-started) for authentication details.
---
-## Create Site
-
-<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
-<div>
-
-```
-POST /api/sites/:orgId
-```
-
-Creates a new site within an organization. Requires admin or owner role in the organization.
-
-### Path Parameters
-
-<TypeTable
- type={{
- orgId: {
- description: 'Organization ID to add the site to',
- type: 'string',
- required: true,
- },
- }}
-/>
-
-### Request Body
-
-<TypeTable
- type={{
- domain: {
- description: 'Site domain',
- type: 'string',
- typeDescription: 'Valid domain format (e.g., example.com)',
- required: true,
- },
- name: {
- description: 'Site display name',
- type: 'string',
- required: true,
- },
- public: {
- description: 'Make analytics publicly accessible',
- type: 'boolean',
- default: false,
- },
- saltUserIds: {
- description: 'Salt user IDs for privacy',
- type: 'boolean',
- default: false,
- },
- blockBots: {
- description: 'Block bot traffic',
- type: 'boolean',
- default: true,
- },
- }}
-/>
-
-### Response
-
-Returns the created site object with the assigned `siteId`.
-
-<TypeTable
- type={{
- siteId: {
- description: 'Numeric site ID (auto-assigned)',
- type: 'number',
- },
- id: {
- description: 'Site UUID',
- type: 'string',
- },
- domain: {
- description: 'Site domain',
- type: 'string',
- },
- name: {
- description: 'Site name',
- type: 'string',
- },
- organizationId: {
- description: 'Organization ID',
- type: 'string',
- },
- createdBy: {
- description: 'User ID who created the site',
- type: 'string',
- },
- public: {
- description: 'Whether analytics are public',
- type: 'boolean',
- },
- saltUserIds: {
- description: 'Whether user IDs are salted',
- type: 'boolean',
- },
- blockBots: {
- description: 'Whether bot traffic is blocked',
- type: 'boolean',
- },
- }}
-/>
-
-</div>
-<div className="flex flex-col gap-4">
-
-<Tabs items={['cURL', 'JavaScript', 'Python', 'PHP', 'Ruby', 'Go', 'Rust', 'Java', '.NET']}>
- <Tab value="cURL">
-```bash title="Request"
-curl -X POST "https://api.rybbit.io/api/sites/org_123" \
- -H "Authorization: Bearer your_api_key_here" \
- -H "Content-Type: application/json" \
- -d '{"domain": "example.com", "name": "My Website", "blockBots": true}'
-```
- </Tab>
- <Tab value="JavaScript">
-```javascript title="Request"
-const orgId = 'org_123';
-const response = await fetch(
- `https://api.rybbit.io/api/sites/${orgId}`,
- {
- method: 'POST',
- headers: {
- 'Authorization': 'Bearer your_api_key_here',
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- domain: 'example.com',
- name: 'My Website',
- blockBots: true
- })
- }
-);
-
-const data = await response.json();
-```
- </Tab>
- <Tab value="Python">
-```python title="Request"
-import requests
-
-org_id = 'org_123'
-response = requests.post(
- f'https://api.rybbit.io/api/sites/{org_id}',
- json={
- 'domain': 'example.com',
- 'name': 'My Website',
- 'blockBots': True
- },
- headers={
- 'Authorization': 'Bearer your_api_key_here'
- }
-)
-
-data = response.json()
-```
- </Tab>
- <Tab value="PHP">
-```php title="Request"
-$orgId = 'org_123';
-$ch = curl_init();
-curl_setopt($ch, CURLOPT_URL, "https://api.rybbit.io/api/sites/{$orgId}");
-curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-curl_setopt($ch, CURLOPT_POST, true);
-curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
- 'domain' => 'example.com',
- 'name' => 'My Website',
- 'blockBots' => true
-]));
-curl_setopt($ch, CURLOPT_HTTPHEADER, [
- 'Authorization: Bearer your_api_key_here',
- 'Content-Type: application/json'
-]);
-
-$response = curl_exec($ch);
-curl_close($ch);
-
-$data = json_decode($response, true);
-```
- </Tab>
- <Tab value="Ruby">
-```ruby title="Request"
-require 'net/http'
-require 'json'
-
-org_id = 'org_123'
-uri = URI("https://api.rybbit.io/api/sites/#{org_id}")
-req = Net::HTTP::Post.new(uri)
-req['Authorization'] = 'Bearer your_api_key_here'
-req['Content-Type'] = 'application/json'
-req.body = {
- domain: 'example.com',
- name: 'My Website',
- blockBots: true
-}.to_json
-
-res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
-data = JSON.parse(res.body)
-```
- </Tab>
- <Tab value="Go">
-```go title="Request"
-orgId := "org_123"
-body := bytes.NewBuffer([]byte(`{
- "domain": "example.com",
- "name": "My Website",
- "blockBots": true
-}`))
-req, _ := http.NewRequest("POST", "https://api.rybbit.io/api/sites/"+orgId, body)
-req.Header.Set("Authorization", "Bearer your_api_key_here")
-req.Header.Set("Content-Type", "application/json")
-
-client := &http.Client{}
-resp, _ := client.Do(req)
-defer resp.Body.Close()
-
-var data map[string]interface{}
-json.NewDecoder(resp.Body).Decode(&data)
-```
- </Tab>
- <Tab value="Rust">
-```rust title="Request"
-let org_id = "org_123";
-let client = reqwest::Client::new();
-let res = client
- .post(format!("https://api.rybbit.io/api/sites/{}", org_id))
- .header("Authorization", "Bearer your_api_key_here")
- .json(&serde_json::json!({
- "domain": "example.com",
- "name": "My Website",
- "blockBots": true
- }))
- .send()
- .await?;
-
-let data: serde_json::Value = res.json().await?;
-```
- </Tab>
- <Tab value="Java">
-```java title="Request"
-String orgId = "org_123";
-HttpClient client = HttpClient.newHttpClient();
-String json = "{\"domain\": \"example.com\", \"name\": \"My Website\", \"blockBots\": true}";
-HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create("https://api.rybbit.io/api/sites/" + orgId))
- .header("Authorization", "Bearer your_api_key_here")
- .header("Content-Type", "application/json")
- .POST(HttpRequest.BodyPublishers.ofString(json))
- .build();
-
-HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
-```
- </Tab>
- <Tab value=".NET">
-```csharp title="Request"
-var orgId = "org_123";
-using var client = new HttpClient();
-client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_key_here");
-
-var content = new StringContent(
- "{\"domain\": \"example.com\", \"name\": \"My Website\", \"blockBots\": true}",
- Encoding.UTF8,
- "application/json"
-);
-
-var response = await client.PostAsync($"https://api.rybbit.io/api/sites/{orgId}", content);
-var data = await response.Content.ReadAsStringAsync();
-```
- </Tab>
-</Tabs>
-
-```json title="Response"
-{
- "siteId": 456,
- "id": "a1b2c3d4e5f6",
- "domain": "example.com",
- "name": "My Website",
- "organizationId": "org_123",
- "createdBy": "user_xyz789",
- "public": false,
- "saltUserIds": false,
- "blockBots": true
-}
-```
-
-</div>
-</div>
-
----
-
## Get Site
<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
diff --git a/server/src/api/sites/addSite.ts b/server/src/api/sites/addSite.ts
index 7c103683e..eb3fb255f 100644
--- a/server/src/api/sites/addSite.ts
+++ b/server/src/api/sites/addSite.ts
@@ -6,7 +6,7 @@ import { sites } from "../../db/postgres/schema.js";
export async function addSite(
request: FastifyRequest<{
Params: {
- orgId: string;
+ organizationId: string;
};
Body: {
domain: string;
@@ -18,7 +18,7 @@ export async function addSite(
}>,
reply: FastifyReply
) {
- const { orgId: organizationId } = request.params;
+ const { organizationId } = request.params;
const { domain, name, public: isPublic, saltUserIds, blockBots } = request.body;
// Validate domain format using regex
diff --git a/server/src/index.ts b/server/src/index.ts
index 9affa58c6..6d30b6118 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -277,7 +277,6 @@ server.delete("/api/session-replay/:sessionId/:siteId", authSite, deleteSessionR
// Sites
server.get("/api/sites/:siteId", publicSite, getSite);
-server.post("/api/sites/:organizationId", orgAdminParams, addSite);
server.put("/api/sites/:siteId/config", adminSite, updateSiteConfig);
server.delete("/api/sites/:siteId", adminSite, deleteSite);
server.get("/api/sites/:siteId/private-link-config", adminSite, getSitePrivateLinkConfig);
@@ -294,6 +293,7 @@ server.delete("/api/sites/:siteId/imports/:importId", adminSite, deleteSiteImpor
// Organizations
server.get("/api/organizations/:organizationId/sites", orgMember, getSitesFromOrg);
+server.post("/api/organizations/:organizationId/sites", orgAdminParams, addSite);
server.get("/api/organizations/:organizationId/members", orgMember, listOrganizationMembers);
server.post("/api/organizations/:organizationId/members", orgMember, addUserToOrganization);