Connecting the Mixpanel API to Google Sheets

Mixpanel is a tool that allows you to analyze how users interact with your product. We can use the Mixpanel API to import data from Mixpanel into Google Sheets. In this tutorial, I’ll show you how to connect the Mixpanel API to Google Sheets in 6 steps:

  1. Install the Apipheny add-on
  2. Create a Project and get the Project ID
  3. Create a Service Account
  4. Choose a Mixpanel endpoint
  5. Enter Your Mixpanel API request into Apipheny
  6. Run the Mixpanel API request in your Google Sheet

Step 1.) Install and open the Apipheny add-on in Google Sheets

To pull data from the Mixpanel API to Google Sheets, first install and open the Apipheny Google Sheets add-on.

Apipheny is a no-code API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs, save API requests, schedule API requests, and more. 

1. Install Apipheny by opening the following link on desktop and then clicking the Install button on the page: https://apipheny.io/install

2. After you’ve installed Apipheny, open a Google Sheet and then click on the Add-Ons or Extensions option in the top menu. In the add-ons menu, you should see Apipheny.

Click Apipheny > Import API to open the Apipheny sidebar in your Google Sheets.

open apipheny

Step 2.) Create a Project and get a Project ID


If you don’t have any projects in your account yet, go to https://mixpanel.com/report and click on the Create project link:

Create project
Create project

If you want to create a new project for working with Apipheny, just click on the current project button in the upper-right corner of the main Mixpanel interface and in the menu that opens, click the Create project button at the bottom:

Create new project
Create new project

A popup will appear, where you’ll need to complete the project’s name, data storage region (US or EU) and timezone. After completing these fields, then click the Create button:

Create project fields
Create project fields

If you want to use one of your existing projects with Apipheny, just click on its name in the same menu that opens from the current project button in the upper-right corner of the main Mixpanel interface:

Use existing project
Use existing project

Now, you’ll need to retrieve and copy your project’s ID. To do so, navigate to your project’s Settings page, by clicking the Settings icon and then the name of your project:

Project's Settings section
Project’s Settings section

After the project’s settings appear, copy the value of the Project ID field and paste it in a safe location, because you’ll need it for most of the API calls you make:

Retrieve the project id
Retrieve the project id

Step 3.) Create a Service Account

Mixpanel uses service accounts as their preferred API authentication method. These accounts are designed to be used when implementing any scripts or backend services.

To create a service account, navigate first to your Organization Settings page, by clicking the Settings icon and then the name of your organization:

Settings section
Settings section

On the Organization Settings page, click Service Accounts in the menu on the left and then the + Add Service Account button in the panel that appears on the right:

Organization Settings page
Organization Settings page

In the popup that appears on the page, give a name to the service account, select the Owner role for both the organization and the project (this gives the account complete access to every available operation), select the project(s) you want to use for Apipheny, choose Never as the account’s expiration interval and then click the Create button:

Create Service Account page
Create Service Account page

Your service account will be created and its username and secret will be shown. Make sure to copy them to a safe location, because you’ll need them later. After you’ve done so, press the Done button to complete the process:

Service Account creation
Service Account creation

Step 4.) Choose a Mixpanel endpoint

In this section, we’ll show you how to browse the Mixpanel API documentation to find the API URL that retrieves the information you need from your account. If you already know your endpoint, or you want to use the same example URL as us, just skip to Step 5.

First, open the Mixpanel API documentation page: https://developer.mixpanel.com/reference/overview

The menu on the left contains the structure of the Mixpanel API functional endpoint groups, while the initial Overview panel on the right shows descriptions for each of these groups:

Mixpanel API documentation page
Mixpanel API documentation page

An example endpoint is Query Profiles, which returns a list of users that fit the specified parameters:

https://mixpanel.com/api/2.0/engage?project_id={your_project_id}

If you use this URL, don’t forget to replace {your_project_id} with the actual value you obtained at the end of Step 2. Do not include the brackets in the final URL.

The endpoint’s documentation contains its HTTP method (POST) and URI, a description of the endpoint’s functionality, a table explaining the accepted parameters, as well as sample requests in Curl and in various programming languages:

Query Profiles endpoint documentation
Query Profiles endpoint documentation

The authentication credentials and the query parameters can be assigned values and you can press the Try It! button under the currently-selected sample request, to perform the call and see the response:

Try it! section for Query Profiles endpoint
Try it! section for Query Profiles endpoint

Base domains for API calls depend on the particular API endpoint functional group you’re using and on your project’s data storage region (US or EU). You can find these base domains on the main Overview panel: https://developer.mixpanel.com/reference/overview

Step 5.) Enter Your Mixpanel API request into Apipheny

Now go back to your Google Sheet and make sure that the Apipheny add-on is open on the Import tab. With the Import tab open, enter these details into the add-on:

Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.

API URL: In Step 4, we explained how you can find the Mixpanel REST API endpoint that you need. Now copy and paste your complete Mixpanel API URL into the Apipheny add-on, where it says API URL Path, followed by any parameters required for your query (if applicable).

For this example, we are using the List Service Accounts For Project endpoint, which retrieves the list of service accounts associated with a specific project. This is what the whole URL looks like:

https://mixpanel.com/api/app/projects/project_id/service-accounts

If you use this URL, replace project_id with the value you obtained at the end of Step 2.

Headers: In the Headers section of Apipheny, add two rows with the following keys and values:

Header 1
Key:
Accept
Value:
application/json

Header 2
Key:
Authorization
Value:
Basic service_account_username:service_account_secret

When entering the second header value into Apipheny, you must replace the service_account_username and service_account_secret values with the values you copied previously, at the end of Step 3.

So the value for Header 2 will be the word “Basic”, a space, then the values for service_account_username and service_account_secret, separated by a colon.

Mixpanel API request entered into Apipheny
Mixpanel API request entered into Apipheny

Step 6.) Run the Mixpanel API request in Your Google Sheet

Finally, the last step is to click the Run button at the bottom of the Apipheny add-on and then wait for the Mixpanel API data to be imported into your Google Sheet. Here’s what our request looked like when completed:

Mixpanel data imported into Google Sheets
Mixpanel data imported into Google Sheets

That’s it! You’ve successfully connected your Mixpanel account to Google Sheets using the Mixpanel API, Google Sheets API, and the Apipheny add-on.

After making a successful request to the Mixpanel API, try querying a different Mixpanel endpoint, or try using one of the more advanced features in the Apipheny add-on.


More API Tutorials

Related Posts