Skip to Content
SimulatorsPostHogPersons and cohorts

Simulators

Persons and cohorts

Use persons and cohorts to test code that follows one visitor across events, reads or edits their profile and sorts people into groups. The setup block keeps your personal API key and the project’s routes in variables that later blocks reuse. The example then captures an event that sets person properties and reads back the person it built:

KEY=phx_rysticexamplepersonalkey000000000000000
TOKEN=phc_93a00453928e7bff26aac13f55056c3e3f5fdd7c2eb
P="$RYSTIC_URL/api/projects/3104"
curl -s -X POST "$RYSTIC_URL/i/v0/e/" -H 'Content-Type: application/json' -d '{"api_key":"'"$TOKEN"'","event":"pricing_viewed","distinct_id":"anon_77","properties":{"$set_once":{"first_page":"/pricing"},"$set":{"plan":"free"}},"timestamp":"2026-02-28T09:00:00Z"}'
# -> {"status":"Ok"}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/?distinct_id=anon_77" | jq -c '.results[] | {uuid, distinct_ids, first_page: .properties.first_page, plan: .properties.plan}'
# -> {"uuid":"bf5cf9c5-0bbc-4802-8000-000000000001","distinct_ids":["anon_77"],"first_page":"/pricing","plan":"free"}

TOKEN is the project API key of the default scenario’s project, 3104. A person is built only when the event’s key belongs to a project in the simulator. An event that sets person properties with a phc_ key that belongs to no project returns Ok, but no person comes from it:

curl -s -X POST "$RYSTIC_URL/i/v0/e/" -H 'Content-Type: application/json' -d '{"api_key":"phc_notaprojectkey0000000000000000000000000000","event":"pricing_viewed","distinct_id":"anon_78","properties":{"$set_once":{"first_page":"/pricing"},"$set":{"plan":"free"}},"timestamp":"2026-02-28T09:00:00Z"}'
# -> {"status":"Ok"}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/?distinct_id=anon_78" | jq '.results | length'
# -> 0

Merge an anonymous visitor into a signed-in user

To test sign-in, send an $identify event under the user’s id with the anonymous id in $anon_distinct_id. The simulator adds the user’s id to the anonymous person, so one person now has both ids. The $set properties of the $identify event apply to that person:

curl -s -X POST "$RYSTIC_URL/i/v0/e/" -H 'Content-Type: application/json' -d '{"api_key":"'"$TOKEN"'","event":"$identify","distinct_id":"user_77","properties":{"$anon_distinct_id":"anon_77","$set":{"email":"ada@example.com"}},"timestamp":"2026-02-28T09:01:00Z"}'
# -> {"status":"Ok"}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/?distinct_id=user_77" | jq -c '.results[] | {uuid, distinct_ids, email: .properties.email}'
# -> {"uuid":"bf5cf9c5-0bbc-4802-8000-000000000001","distinct_ids":["anon_77","user_77"],"email":"ada@example.com"}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/" | jq -c '[.results[].distinct_ids]'
# -> [["anon_77","user_77"],["user_1"]]

The list still has two persons: the merged visitor and user_1, whom the default scenario seeds.

Change a person’s properties

Set one property with update_property and remove one with delete_property, both addressed by the person’s uuid. Then read the person and the values the project has for a property:

U=bf5cf9c5-0bbc-4802-8000-000000000001
curl -s -X POST "$P/persons/$U/update_property/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"key":"plan","value":"pro"}' -w '%{http_code}\n'
# -> 202
curl -s -X POST "$P/persons/$U/delete_property/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"$unset":"first_page"}' -w '%{http_code}\n'
# -> {"success":true}
# -> 201
curl -s -H "Authorization: Bearer $KEY" "$P/persons/$U/" | jq -c '.properties | {plan, first_page}'
# -> {"plan":"pro","first_page":null}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/values/?key=plan" | jq -c .results
# -> [{"count":1,"name":"pro"}]

The update_property request returns 202 with an empty body, so check the change by reading the person again.

Group persons in a static cohort

Create a cohort with is_static set to true, then add persons to it by uuid. To see which cohorts a person belongs to, pass their uuid as person_id to /persons/cohorts/:

curl -s -X POST "$P/cohorts/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"name":"Beta testers","is_static":true}' | jq -c '{id, name, is_static}'
# -> {"id":1,"name":"Beta testers","is_static":true}
curl -s -X PATCH "$P/cohorts/1/add_persons_to_static_cohort/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"person_ids":["'"$U"'","c8f05605-05bf-4684-a307-4ae5de0f30fc"]}'
# -> {"success":true}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/cohorts/?person_id=$U" | jq -c '[.results[] | {id, name}]'
# -> [{"id":1,"name":"Beta testers"}]
curl -s -X PATCH "$P/cohorts/1/remove_person_from_static_cohort/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"person_id":"'"$U"'"}'
# -> {"success":true}
curl -s -H "Authorization: Bearer $KEY" "$P/persons/cohorts/?person_id=$U" | jq -c .results
# -> []
curl -s -X PATCH "$P/cohorts/1/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"name":"Beta group"}' | jq -c '{id, name}'
# -> {"id":1,"name":"Beta group"}
curl -s -H "Authorization: Bearer $KEY" "$P/cohorts/" | jq -c '[.results[] | {id, name}]'
# -> [{"id":1,"name":"Beta group"}]

Check membership through /persons/cohorts/, not the cohort’s count; Limitations explains why.

Delete persons

Send bulk_delete a list of distinct_ids or a list of person uuid values in ids. A request may send both. Deleting by any one of a merged person’s ids removes the whole person:

curl -s -X POST "$P/persons/bulk_delete/" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"distinct_ids":["user_77"]}' -w '%{http_code}\n'
# -> {"deletion_errors":[],"events_queued_for_deletion":false,"persons_deleted":0,"persons_found":1,"persons_queued_for_deletion":1,"recordings_queued_for_deletion":false}
# -> 202
curl -s -H "Authorization: Bearer $KEY" "$P/persons/" | jq -c '[.results[].distinct_ids]'
# -> [["user_1"]]

The person is gone from the next read, even though the response reports it as queued rather than deleted.

Start from a merged visitor or an existing cohort

Two scenarios seed this state for you, each in its own project. Loading a scenario replaces everything the earlier blocks built. The posthog_identify_handoff scenario has one visitor who browsed anonymously and then signed in, in project 3102:

curl -s -X POST "$RYSTIC_URL/_rystic/scenario" -o /dev/null -w '%{http_code}\n' -d '{"name":"posthog_identify_handoff"}'
# -> 204
curl -s -H "Authorization: Bearer $KEY" "$RYSTIC_URL/api/projects/3102/persons/" | jq -c '.results[] | {name, distinct_ids, is_identified}'
# -> {"name":"dana.reyes@example.com","distinct_ids":["user_4821","019c940f-f640-715d-837b-7da73b153d6c"],"is_identified":true}

The posthog_signup_funnel scenario has three visitors in project 3101. One of them belongs to the dynamic cohort “Signed up this week”:

curl -s -X POST "$RYSTIC_URL/_rystic/scenario" -o /dev/null -w '%{http_code}\n' -d '{"name":"posthog_signup_funnel"}'
# -> 204
curl -s -H "Authorization: Bearer $KEY" "$RYSTIC_URL/api/projects/3101/cohorts/" | jq -c '[.results[] | {id, name, is_static, count}]'
# -> [{"id":4201,"name":"Signed up this week","is_static":false,"count":1}]
curl -s -H "Authorization: Bearer $KEY" "$RYSTIC_URL/api/projects/3101/persons/cohorts/?person_id=2caae4c1-a006-4c1f-aa67-18ee3e9a165f" | jq -c '[.results[].name]'
# -> ["Signed up this week"]

Reference

Ids are fixed, so a test can name them before it runs. The first person the simulator builds has uuid bf5cf9c5-0bbc-4802-8000-000000000001, and the next ones count up from it. The first cohort you create gets id 1.

RequestStatusBody
POST /persons/{uuid}/update_property/202empty
POST /persons/{uuid}/delete_property/201{"success":true}
PATCH /cohorts/{id}/add_persons_to_static_cohort/200{"success":true}
PATCH /cohorts/{id}/remove_person_from_static_cohort/200{"success":true}
POST /persons/bulk_delete/202counts of persons found and queued

Seed persons and cohorts of your own as described in Seeding state.

Last updated on