Question

Python2.7 posting to user in Mixpanel - Not sure what I am doing wrong

  • 2 August 2019
  • 1 reply
  • 35 views

Badge

Hi Everyone,
I am having some trouble adding data to a Mixpanel user. I am hoping I can get some guidance here.
I am trying the following, however when I go into the mixpanel I don't see any of this information online.
What am I doing wrong. I don't get any error. I am fairly confident of the key I am using. I used the API Secret.

api_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
mp = Mixpanel(api_secret)
x = mp.people_set(user_id,{
"subscription_status": 153,
"subscription_start": datetime.now(),
"subscription_end": datetime.now() + timedelta(days=90)
})


1 reply

Userlevel 3
Badge

Hey @admurray,

To update people profiles in bulk, you will need to update them using the Mixpanel API module of people_set_once. It will require you to install the Mixpanel API module on your machine via the terminal using:

pip install mixpanel-api

From there you would need a Python script that looks something like this:

from mixpanel_api import Mixpanel

if __name__ == '__main__':
    credentials = [
        {'API_secret': 'FILL THIS IN',
        'token': 'FILL THIS IN'}
    ]

    parameters = {'filter_by_cohort': 'FILL THIS IN'}

    for project in credentials:

        i = Mixpanel(project['API_secret'],project['token'], debug=True)
        i.people_set_once({'PROPERTY NAME':'PROPERTY VALUE'}, query_params=parameters)

To find the filter_by_cohort value, you can look at the XHR request of an Explore report that contains the profiles you want to add a people property to.

  • This is done by Pressing CMD+option+J on Chrome for macOS > selecting the Network tab > search for the "engage" endpoint in the list of requests.
  • If you are using behaviors in your query_params you must specify a timezone_offset. Your project timezone can be found in Project settings.
    • I set debug=True in the module initialization, so you can see if the script is working or failing.
  • On the i.people_set_once call, you will need to fill in the name of the property you want to add and the value of the property. There is an example here of
    {'chiles':'red'}

After that the only thing left for you to do would be to fill in the API secret and token. To find these you need to select the settings gear icon at the top right hand corner of the Mixpanel UI and choose "Project settings".

Hopefully this helps!


Reply