Solved

[Dashboard API] Cannot filter events by Amplitude Event Name

  • 21 January 2022
  • 9 replies
  • 99 views

Badge +1

Hi, everyone!

I’m trying to create api request for this conditions:

I’m using JS fetch method.

This request fails:

fetch('https://amplitude.com/api/2/events/segmentation?' + new URLSearchParams({
e: '{"event_type":"_all","filters":[{"subprop_type":"event","subprop_key":"Event Name","subprop_op":"is","subprop_value":["Test"]}]}',
m: 'uniques',
start: '20210101',
end: '20220101',
i: 30
}).toString(), {
method: 'GET',
headers: {
accept: '*/*',
'Content-Type': 'application/json',
Authorization: 'Basic API_KEY:SECRET_KEY'
}
})

If I’m using custom user property, everything works. 

fetch('https://amplitude.com/api/2/events/segmentation?' + new URLSearchParams({
e: '{"event_type":"_all","filters":[{"subprop_type":"user","subprop_key":"gp:Is Tester","subprop_op":"is","subprop_value":["(none)"]}]}',
m: 'uniques',
start: '20210101',
end: '20220101',
i: 30
}).toString(), {
method: 'GET',
headers: {
accept: '*/*',
'Content-Type': 'application/json',
Authorization: 'Basic API_KEY:SECRET_KEY'
}
})

I have issue with Amplitude Event Name. 

Thanks for any help!

icon

Best answer by gapon2401 24 January 2022, 10:12

View original

9 replies

Userlevel 4
Badge +2

@gapon2401 Are you receiving an error response with the failure? If so, what does it say?

Badge +1

I recieve HTTP 400: Bad Request
 

Userlevel 7
Badge +10

Hey @gapon2401,

Afaik, “Event Name” is a UI based property by Amplitude and don’t think it can be used explicitly in API calls.

In the first call, it seems like you are trying to use “Event Name” as an event property by specifying its value as “Test”, whereas Test is actually your event name in itself.

If you are replicating the screenshot, a better way would be to directly use the event name “Test”

"event_type":"Test"

and then apply the relevant user property/ event property filters.

The second call works fine because you are querying “Any Event” ( _all ) where your user property

“Is Tester” = none

 

Let me know if this works for you.

Badge +1

@Saish Redkar Thank you for your reply!

I need to filter events with operator “is” or “is not”. That’s why I tried to use amplitute property “Event name”.

Here is the screenshot of desired result:

So, I use “Any event” and “Event name” to combine the events I need. I don’t know, how to make it other way with API.

Userlevel 7
Badge +10

Hey @gapon2401 

That’s a fair use case.
I’m not sure if we can replicate that in the API call since I haven’t come across any parameter to use the “Event Name” property explicitly in the docs. Currently, the Dashboard REST API supports segmentation by up to two events only.

Userlevel 4
Badge +2

Hi @gapon2401!

@Saish Redkar is right in that this is currently not possible in the API call. Maybe you can elaborate a bit on the objective of what you’re trying to do, so we can help brainstorm other ways of achieving it? 

Badge +1

Hi, @ning.chang! I need to exclude the list of events from the results. This is he main goal.

I see two options:

  1. Long way: Use Export API and filter the data as I want.
  2. Short way: Create charts with desired conditions and use query:
    https://amplitude.com/api/3/chart/CHART_ID_HERE/query

Then, after the requests to  several charts, I will combine the data as I need.

 

Userlevel 4
Badge +2

Gotcha! I see these two options too. The second one seems cleaner to me, as you can exclude using the filters available within the platform UI to perform the queries you want. 

Badge +1

Yes, I agree! Less work, using the power of platform.

Thanks everyone for the help!  

Reply