Solved

event array is not valid json

  • 16 November 2021
  • 1 reply
  • 31 views

I am getting the event array is not valid json when I pass the event name to the export api. I am passing

querystring = {"to_date":"2020-12-31","from_date":"2020-12-30","limit":"100",'event':'login'}

Can you help to resolve the issue ?

icon

Best answer by nick 22 November 2021, 16:54

View original

1 reply

Userlevel 2
Badge +2

Hey @vijay.pattar  --

It looks like you’re trying to use the /export API:
https://developer.mixpanel.com/reference/raw-event-export

I believe you’re doing this

curl --request GET \
--url 'https://data.mixpanel.com/api/2.0/export?from_date=2021-04-10&to_date=2021-04-20&limit=100&event=foo' \
--header 'Accept: application/json' \
--header 'Authorization: Basic NDg2OGE3YTFjN2M4ZTBlZGNiODBjYjVmMWViOGJiMWU6'

and getting:

400: event array is not valid json

What you actually need to be doing is 

curl --request GET \
--url 'https://data.mixpanel.com/api/2.0/export?from_date=2021-04-10&to_date=2021-04-20&limit=100&event=%5B%22foo%22%5D' \
--header 'Accept: application/json' \
--header 'Authorization: Basic NDg2OGE3YTFjN2M4ZTBlZGNiODBjYjVmMWViOGJiMWU6'

notice the weird event=%5B%22foo%22%5D at the end of the request in #2. This is construction is event=["foo"] … just URL encoded … I believe you’re doing event=foo (which doesn’t work)

 

for the event param in your /export request, you need to include a valid JSON array of strings… so in your case it would be event:["login"] rather than event:'login' (double quotes and brackets!) so instead of:

curl --request GET \
--url 'https://data.mixpanel.com/api/2.0/export?from_date=2020-12-30&to_date=2020-12-31&limit=100&event=login' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <<redacted>>'

which returns 400, try

curl --request GET \
--url 'https://data.mixpanel.com/api/2.0/export?from_date=2020-12-30&to_date=2020-12-31&limit=100&event=%5B%22login%22%5D' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <<redacted>'

which returns 200 and gives you data. 

 

Let me know if you have any questions!

Reply