How to write the correct payload in Python when using filter_by_cohort in Query Profiles?
Hi 石川 明., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
To write the correct payload in Python when using filter_by_cohort
in Query Profiles, you need to format the cohort filter as a JSON string. Here's how you can do it:LBKSfilter_by_cohort = '{"id": 12345}'LBKS
Replace 12345 with the actual cohort ID you want to use. This format is specified in the Exporting Profiles documentation, which states::LBKS"Example:: filter_by_cohort='{"id":12345}'
"You would then include this in your API request. For example, if you're using the requests
library in Python, your code might look something like this:LBKSimport requestsLBKSurl = '[https://mixpanel.com/api/2.0/engage](https://mixpanel.com/api/2.0/engage)' headers = { 'Authorization': 'Basic YOUR_TOKEN', 'Content-Type': 'application/x-www-form-urlencoded' } data = { 'filter_by_cohort': '{"id": 12345}' }LBKSresponse = [requests.post](http://requests.post)(url, headers=headers, data=data)LBKS
Remember to replace YOUR_TOKEN
with your actual Mixpanel API token, and 12345
with your actual cohort ID.If you need to find the cohort ID, you can use the List Saved Cohorts endpoint, which will return a list of all cohorts in your project, including their IDs.Exporting Profiles
List Saved Cohorts
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.