:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(posthog): add person split docs (#61756)
Zach Brown1cca01a8ea2a
diff --git a/posthog/api/person.py b/posthog/api/person.pyindex 811cb1fbf3d2..87b110ba5077 100644--- a/posthog/api/person.py+++ b/posthog/api/person.py@@ -231,6 +231,42 @@ class PersonBulkDeleteResponseSerializer(serializers.Serializer):)+class PersonSplitRequestSerializer(serializers.Serializer):+ main_distinct_id = serializers.CharField(+ required=False,+ allow_null=True,+ help_text=(+ "The distinct_id to **keep** on this person; every *other* distinct_id is moved "+ "to its own new single-id person. If omitted, the first distinct_id on the person "+ "is used and the person's properties are wiped. "+ "To surgically *remove* one or more distinct_ids while leaving the merge intact, "+ "use `distinct_ids_to_split` instead — these parameters are inverses of each other "+ "and cannot be combined."+ ),+ )+ distinct_ids_to_split = serializers.ListField(+ child=serializers.CharField(),+ required=False,+ allow_null=True,+ help_text=(+ "List of distinct_ids to **move off** this person onto new single-id persons. "+ "The original person keeps every other distinct_id and its properties. New persons "+ "are created with deterministic UUIDs derived from `(team_id, distinct_id)`. "+ "Cannot be combined with `main_distinct_id`."+ ),+ )+++class PersonSplitResponseSerializer(serializers.Serializer):+ success = serializers.BooleanField(+ help_text=(+ "Always `true` when the split task was enqueued. The split itself runs "+ "asynchronously — a 201 response means the task was accepted, not that the "+ "merge state has already been updated."+ )+ )++class AsyncDeletionStatusSerializer(serializers.Serializer):person_uuid = serializers.CharField(source="key", help_text="The UUID of the person whose events are queued for deletion."@@ -799,6 +835,27 @@ class PersonViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):resp["Cache-Control"] = "max-age=10"return resp+ @extend_schema(+ description=(+ "Split distinct_ids off a merged person. Two mutually exclusive modes:\n\n"+ "- **`distinct_ids_to_split`** (recommended for surgical edits): moves only the "+ "listed distinct_ids off this person onto new single-id persons. The original "+ "person keeps every other distinct_id and its properties.\n"+ "- **`main_distinct_id`** (legacy semantics): keeps only the specified distinct_id "+ "on this person; moves every *other* distinct_id off onto its own new person. If "+ "omitted, the person's properties are wiped and the first distinct_id is treated "+ "as the one to keep.\n\n"+ "The split runs asynchronously: a 201 response means the task was enqueued. "+ "Newly-created split-off persons get a deterministic UUID derived from "+ "`(team_id, distinct_id)`, so they can be located client-side without polling. "+ "If you need to delete a split-off person after this call, prefer looking it up by "+ "that deterministic UUID rather than by distinct_id, since the latter still "+ "resolves to the original merged person until the async task completes."+ ),+ request=PersonSplitRequestSerializer,+ responses={201: PersonSplitResponseSerializer},+ parameters=[_PERSON_ID_PARAMETER],+ )@action(methods=["POST"], detail=True, required_scopes=["person:write"])def split(self, request: request.Request, pk=None, **kwargs) -> response.Response:person: Person = self.get_object()diff --git a/products/persons/frontend/generated/api.schemas.ts b/products/persons/frontend/generated/api.schemas.tsindex 504bb4de4268..11c9dea9424d 100644--- a/products/persons/frontend/generated/api.schemas.ts+++ b/products/persons/frontend/generated/api.schemas.ts@@ -232,6 +232,24 @@ export interface PersonDeletePropertyRequestApi {$unset: string}+export interface PersonSplitRequestApi {+ /**+ * The distinct_id to **keep** on this person; every *other* distinct_id is moved to its own new single-id person. If omitted, the first distinct_id on the person is used and the person's properties are wiped. To surgically *remove* one or more distinct_ids while leaving the merge intact, use `distinct_ids_to_split` instead — these parameters are inverses of each other and cannot be combined.+ * @nullable+ */+ main_distinct_id?: string | null+ /**+ * List of distinct_ids to **move off** this person onto new single-id persons. The original person keeps every other distinct_id and its properties. New persons are created with deterministic UUIDs derived from `(team_id, distinct_id)`. Cannot be combined with `main_distinct_id`.+ * @nullable+ */+ distinct_ids_to_split?: string[] | null+}++export interface PersonSplitResponseApi {+ /** Always `true` when the split task was enqueued. The split itself runs asynchronously — a 201 response means the task was accepted, not that the merge state has already been updated. */+ success: boolean+}+export interface PersonUpdatePropertyRequestApi {/** The property key to set. */key: stringdiff --git a/products/persons/frontend/generated/api.ts b/products/persons/frontend/generated/api.tsindex 50ecf69b7f0d..0b0136764b9c 100644--- a/products/persons/frontend/generated/api.ts+++ b/products/persons/frontend/generated/api.ts@@ -17,6 +17,8 @@ import type {PersonDeletePropertyRequestApi,PersonPropertiesAtTimeResponseApi,PersonRecordApi,+ PersonSplitRequestApi,+ PersonSplitResponseApi,PersonUpdatePropertyRequestApi,PersonsActivityRetrieveParams,PersonsAllActivityRetrieveParams,@@ -298,7 +300,7 @@ export const personsPropertiesTimelineRetrieve = async (})}-export const getPersonsSplitCreateUrl = (projectId: string, id: number, params?: PersonsSplitCreateParams) => {+export const getPersonsSplitCreateUrl = (projectId: string, id: string, params?: PersonsSplitCreateParams) => {const normalizedParams = new URLSearchParams()Object.entries(params || {}).forEach(([key, value]) => {@@ -315,20 +317,25 @@ export const getPersonsSplitCreateUrl = (projectId: string, id: number, params?:}/**- * This endpoint is meant for reading and deleting persons. To create or update persons, we recommend using the [capture API](https://posthog.com/docs/api/capture), the `$set` and `$unset` [properties](https://posthog.com/docs/product-analytics/user-properties), or one of our SDKs.+ * Split distinct_ids off a merged person. Two mutually exclusive modes:++- **`distinct_ids_to_split`** (recommended for surgical edits): moves only the listed distinct_ids off this person onto new single-id persons. The original person keeps every other distinct_id and its properties.+- **`main_distinct_id`** (legacy semantics): keeps only the specified distinct_id on this person; moves every *other* distinct_id off onto its own new person. If omitted, the person's properties are wiped and the first distinct_id is treated as the one to keep.++The split runs asynchronously: a 201 response means the task was enqueued. Newly-created split-off persons get a deterministic UUID derived from `(team_id, distinct_id)`, so they can be located client-side without polling. If you need to delete a split-off person after this call, prefer looking it up by that deterministic UUID rather than by distinct_id, since the latter still resolves to the original merged person until the async task completes.*/export const personsSplitCreate = async (projectId: string,- id: number,- personRecordApi?: NonReadonly<PersonRecordApi>,+ id: string,+ personSplitRequestApi?: PersonSplitRequestApi,params?: PersonsSplitCreateParams,options?: RequestInit-): Promise<void> => {- return apiMutator<void>(getPersonsSplitCreateUrl(projectId, id, params), {+): Promise<PersonSplitResponseApi> => {+ return apiMutator<PersonSplitResponseApi>(getPersonsSplitCreateUrl(projectId, id, params), {...options,method: 'POST',headers: { 'Content-Type': 'application/json', ...options?.headers },- body: JSON.stringify(personRecordApi),+ body: JSON.stringify(personSplitRequestApi),})}diff --git a/products/persons/frontend/generated/api.zod.ts b/products/persons/frontend/generated/api.zod.tsindex 1c34487d7713..9c68dbfeefdf 100644--- a/products/persons/frontend/generated/api.zod.ts+++ b/products/persons/frontend/generated/api.zod.ts@@ -39,13 +39,26 @@ export const PersonsDeletePropertyCreateBody = /* @__PURE__ */ zod.object({})/**- * This endpoint is meant for reading and deleting persons. To create or update persons, we recommend using the [capture API](https://posthog.com/docs/api/capture), the `$set` and `$unset` [properties](https://posthog.com/docs/product-analytics/user-properties), or one of our SDKs.+ * Split distinct_ids off a merged person. Two mutually exclusive modes:++- **`distinct_ids_to_split`** (recommended for surgical edits): moves only the listed distinct_ids off this person onto new single-id persons. The original person keeps every other distinct_id and its properties.+- **`main_distinct_id`** (legacy semantics): keeps only the specified distinct_id on this person; moves every *other* distinct_id off onto its own new person. If omitted, the person's properties are wiped and the first distinct_id is treated as the one to keep.++The split runs asynchronously: a 201 response means the task was enqueued. Newly-created split-off persons get a deterministic UUID derived from `(team_id, distinct_id)`, so they can be located client-side without polling. If you need to delete a split-off person after this call, prefer looking it up by that deterministic UUID rather than by distinct_id, since the latter still resolves to the original merged person until the async task completes.*/export const PersonsSplitCreateBody = /* @__PURE__ */ zod.object({- properties: zod- .unknown()- .optional()- .describe('Key-value map of person properties set via $set and $set_once operations.'),+ main_distinct_id: zod+ .string()+ .nullish()+ .describe(+ "The distinct_id to \*\*keep\*\* on this person; every \*other\* distinct_id is moved to its own new single-id person. If omitted, the first distinct_id on the person is used and the person's properties are wiped. To surgically \*remove\* one or more distinct_ids while leaving the merge intact, use `distinct_ids_to_split` instead — these parameters are inverses of each other and cannot be combined."+ ),+ distinct_ids_to_split: zod+ .array(zod.string())+ .nullish()+ .describe(+ 'List of distinct_ids to \*\*move off\*\* this person onto new single-id persons. The original person keeps every other distinct_id and its properties. New persons are created with deterministic UUIDs derived from `(team_id, distinct_id)`. Cannot be combined with `main_distinct_id`.'+ ),})/**diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 60c29689fdcb..ea94fb33732c 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -34112,6 +34112,24 @@ export namespace Schemas {point_in_time_metadata: PersonPropertiesAtTimeMetadata;}+ export interface PersonSplitRequest {+ /**+ * The distinct_id to **keep** on this person; every *other* distinct_id is moved to its own new single-id person. If omitted, the first distinct_id on the person is used and the person's properties are wiped. To surgically *remove* one or more distinct_ids while leaving the merge intact, use `distinct_ids_to_split` instead — these parameters are inverses of each other and cannot be combined.+ * @nullable+ */+ main_distinct_id?: string | null;+ /**+ * List of distinct_ids to **move off** this person onto new single-id persons. The original person keeps every other distinct_id and its properties. New persons are created with deterministic UUIDs derived from `(team_id, distinct_id)`. Cannot be combined with `main_distinct_id`.+ * @nullable+ */+ distinct_ids_to_split?: string[] | null;+ }++ export interface PersonSplitResponse {+ /** Always `true` when the split task was enqueued. The split itself runs asynchronously — a 201 response means the task was accepted, not that the merge state has already been updated. */+ success: boolean;+ }+export interface PersonUpdatePropertyRequest {/** The property key to set. */key: string;