How to give API access to a service account? The query is returning an HTML login page instead of JSON.
Hi Khayalethu L., 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 give API access to a Mixpanel service account and avoid receiving an HTML login page (which usually means authentication failed), follow these steps: 1. Create a Service Account - Go to your Organization settings or Project settings and create a service account. Assign the appropriate role and project access during creation. - When you create the service account, you will receive a username and a secret. Store the secret securely, as you cannot retrieve it again later [Service Accounts].2. Use HTTP Basic Authentication - API requests must use HTTP Basic Auth with the service account's username and secret. - You can provide credentials either as plain text or base64-encoded, but both are accepted by Mixpanel. Example using cURL:
sh
curl [https://mixpanel.com/api/app/me](https://mixpanel.com/api/app/me) \
--user "<serviceaccount_username> :<serviceaccount_secret> "
```LBKS Or using the header directly:
sh curl https://mixpanel.com/api/app/me --header 'authorization: Basic <serviceaccount_username> :<serviceaccount_secret> '
```LBKS import requests
requests.get(
'[https://mixpanel.com/api/app/me](https://mixpanel.com/api/app/me)',
auth=('<serviceaccount_username> ', '<serviceaccount_secret> '),
)
```LBKS [[Service Accounts Authentication](https://github.com/mixpanel/docs/blob/main/reference/Mixpanel%20APIs/authentication/service-accounts.md)]LBKS3. **Check Permissions**
- Ensure the service account has the necessary permissions (role: admin or owner) for the actions you want to perform.
- If you are modifying service accounts or accessing sensitive data, the service account must have the correct role [[Service Accounts API](https://github.com/mixpanel/docs/blob/main/reference/Service%20Accounts%20API/service-accounts-api.md)].LBKS4. **Common Issue: HTML Login Page**
- If you receive an HTML login page, it means authentication failed. Double-check that:
- You are using the correct username and secret.
- You are using HTTP Basic Auth, not a session or browser-based login.
- The service account has not expired or been deleted.LBKSIf you follow these steps and use the correct credentials with HTTP Basic Auth, your API requests should return JSON responses, not an HTML login page. If issues persist, verify the credentials and permissions, and ensure you are not using a browser session or expired credentials [[Service Accounts](https://github.com/mixpanel/docs/blob/main/reference/Mixpanel%20APIs/authentication/service-accounts.md)].
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.