Mixpanel Community Icon

Fixing the API Request for Mixpanel Profile Retrieval Issues

·
·

I am attempting to request profiles from the api and unfortunately are not able to get the where filter to work. I am doing the following:

last_seen_after = "2025-03-01"
params = {
  "project_id": self.project_id,
  "page_size": page_size,
  "page": page
}

if last_seen_after:
  params["where"] = f'properties["$last_seen"] > "{last_seen_after}"'

response = requests.get(
    "https://mixpanel.com/api/2.0/engage",
    params=params,
    auth=(self.api_secret, ''),
    timeout=120,
)

It is always returning 0 records. I have verified that there are users that would qualify for this request. I have also tried passing the last_seen_after as a unix timestamp and it does not work. What am I missing? How can I fix my request to work properly?

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Hi Kale, 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

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    I can see you're having trouble with the Mixpanel Engage API query. There are a few issues with your code that might be causing the problem: 1. The formatting of your where parameter is incorrect. When using the Query API for profiles, the syntax needs to be properly formatted.2. The > in your code is an HTML entity for the greater than symbol (> ), which won't work correctly in this context.3. You might need to use a proper session ID approach for pagination as described in the Mixpanel documentation.Here's how you can fix your request: LBKSlast_seen_after = "2025-03-01" params = { "project_id": self.project_id, "page_size": page_size, "page": page }LBKSif last_seen_after: params["where"] = f'properties["$last_seen"] > "{last_seen_after}"'LBKSresponse = requests.get( "[https://mixpanel.com/api/2.0/engage](https://mixpanel.com/api/2.0/engage)", params=params, auth=(self.api_secret, ''), timeout=120, )LBKSKey changes: - Replaced > with the actual > symbol - Removed the angle brackets from the URLIf you're still having issues, consider these additional points: 1. Make sure your date format is correct. You might want to try using a Unix timestamp instead, as Mixpanel often uses timestamps internally.2. Verify that your API credentials have the proper permissions to access profile data.3. Follow the pagination approach described in the Query Profiles documentation to retrieve all records.4. Check if you're hitting the rate limit (60 queries per hour with a maximum of 5 concurrent queries).5. Ensure your project has the correct data residency setting if you're in the EU or India regions, as this affects the API endpoint.If you continue to have issues, you might want to reach out to Mixpanel Support or join the Mixpanel Community Slack for more specific assistance.

    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.

  • Avatar of Kale
    Kale
    ·
    ·

    kapa.ai datetimes need to be formatted like the following "2025-03-01T00:00:00"

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Let me check the knowledge base for you again. One moment! 📚

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Thank you for providing that clarification. You're right about the datetime format for Mixpanel's API. When working with the Engage API, using the proper datetime format is crucial for the query to work correctly.For your query with the where parameter, you should format your datetime as "2025-03-01T00:00:00" instead of just "2025-03-01". This ISO 8601 format with the time component is what Mixpanel expects when filtering by date properties.Here's how your updated code should look: LBKSlast_seen_after = "2025-03-01T00:00:00" params = { "project_id": self.project_id, "page_size": page_size, "page": page }LBKSif last_seen_after: params["where"] = f'properties["$last_seen"] > "{last_seen_after}"'LBKSresponse = requests.get( "[https://mixpanel.com/api/2.0/engage](https://mixpanel.com/api/2.0/engage)", params=params, auth=(self.api_secret, ''), timeout=120, )LBKSThis proper datetime formatting should help your query return the expected results when filtering profiles by their last seen date.

    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.