datacub التوثيق
المرجع
Markdown

مرجع الـ API

اقرأ تحليلاتك وتعامل مع طلبات الأشخاص عن طريق HTTP، من السيرفر حقك. المواصفة المقروءة آليًا هي /openapi.json (OpenAPI 3.1)؛ وهذي الصفحة مولّدة منها.

المصادقة

استخدم مفتاح قراءة (rk_). لوحة التحكم ما تسوّي مفاتيح قراءة جديدة: المفتاح اللي عندك يظل شغال، ومكانه السيرفر حقك، وأبد لا تحطه في متصفح أو تطبيق. ولو تبي تتعامل مع بيانات شخص بدون مفتاح، استخدم بيانات شخص واحد في الإعدادات، الخصوصية.

  • /api/backend/... ياخذ المفتاح كـ Authorization: Bearer rk_....
  • نقاط التحليلات تاخذ جلسة: POST /api/session مع المفتاح يرجّع كوكي جلسة للاستدعاءات اللي بعده.

أدوات الذكاء الاصطناعي تربط بـ /mcp وتسجّل دخول بـ OAuth بدالها: شوف MCP. وأي مسار يطلب معرّف مشروع، يقبل المعرّف القصير (8 أحرف) مثل الطويل.

نقاط النهاية

POST /api/session

Open a session with a read key

  • Body: JSON, schema in /openapi.json
  • Responses: 200 Sets the xs session cookie; 401; 429

DELETE /api/session

Close the session

  • Auth: session cookie from POST /api/session
  • Responses: 200 Closed

GET /api/projects

The organisation's projects

  • Auth: session cookie from POST /api/session
  • Responses: 200 Your projects, each with your role on it; 401

POST /api/projects/{id}/query

Ask one analytics question. The body is a typed query model (never SQL). People, event and session lists need the analyst role. Errors are codes such as invalid_query, range_too_long, busy (429) or timeout (504).

  • Auth: session cookie from POST /api/session
  • Parameters: id (path, required)
  • Body: JSON, schema in /openapi.json
  • Responses: 200 {meta, data}; data depends on the kind; 400; 401; 403; 404; 429

DELETE /api/backend/projects/{id}/persons/{type}/{pid}

Delete a person's data. A Registered user (type user) with every browser and phone linked to them, or a Guest (type browser)

  • Auth: rk_ read key allowed to handle person requests; server only
  • Parameters: id (path, required), type (path, required), pid (path, required)
  • Responses: 202 {id, status}: status deleted, or held during a legal hold; 400; 401; 403; 429

GET /api/backend/projects/{id}/persons/{type}/{pid}/export

Export a person's data. Everything datacub holds about them, as one JSON document

  • Auth: rk_ read key allowed to handle person requests; server only
  • Parameters: id (path, required), type (path, required), pid (path, required)
  • Responses: 200 datacub.person_export.v1; 400; 401; 403; 429

POST /api/backend/projects/{id}/consent/revoke

Report a withdrawal of consent. Deletes what was collected about the person, as a deletion does

  • Auth: rk_ read key allowed to handle person requests; server only
  • Parameters: id (path, required)
  • Body: JSON, schema in /openapi.json
  • Responses: 202 {id, status}: status deleted, or held during a legal hold; 400; 401; 403; 429

DELETE /api/backend/projects/{id}/tombstones/user/{pid}

Allow a deleted user ID again. Events for this user ID are accepted again from now on; nothing deleted returns

  • Auth: rk_ read key allowed to handle person requests; server only
  • Parameters: id (path, required), pid (path, required)
  • Responses: 200 {ok: true}; 400; 401; 403; 404; 429

POST /mcp

MCP server (Streamable HTTP, JSON-RPC 2.0). Model Context Protocol for AI tools. Every number is exact, the same as the dashboard, and every answer carries a url to the same view. Read only unless the connection was allowed to make changes (scope write:events) and the person is an analyst or above. People one by one (find_people, get_person) need the analyst role; email, name and phone never leave. ?readonly=1, ?features= and ?tools= narrow the tools. 300 requests a minute per connection.

  • Auth: an OAuth access token (the client signs in through /.well-known/oauth-protected-resource/mcp), or a datacub_mcp_ token
  • Body: JSON, schema in /openapi.json
  • Responses: 200 JSON-RPC response; 401; 429

إرسال الأحداث

الـ SDK يرسل POST /v1/batch إلى خادم الاستقبال، ولين 100 حدث. ما تستدعيه بنفسك؛ وإذا مرّرته عن طريق بروكسي، مرّر الجسم وحالة الرد (ومنها Retry-After) زي ما هم بدون تعديل. الردود مذكورة في حل المشاكل.