Solved

Creating a behavioral cohort via API

  • 16 March 2021
  • 5 replies
  • 165 views

Userlevel 7
Badge +4

Hi everyone,

Is there way to programmatically create a behavioral cohort via some API endpoint?

I have used the Dashboard REST API to build some custom event charts for some of my use cases, but was curious to know if we can input some basic parameters and clauses in a similar way to create cohorts as well.

Thanks!

 

icon

Best answer by eddie.gaona 18 March 2021, 23:47

View original

5 replies

Userlevel 4
Badge +4

Hello Saish!

Amplitude offers the Behavioral Cohorts API. With this API you can create cohorts and/or add users to already existing cohorts.

The documentation is in the developers center, here.

Userlevel 7
Badge +4

Hi @eddie.gaona ,
Thanks for your response. Most of the references in the doc are for listing all the existing cohorts , fetching a single cohort and refreshing a cohort/uploading IDs. 

I’m not able to find any end point in there using which I can create and save a cohort by supplying some parameters as in below : 

 

Userlevel 4
Badge +4

Hello @Saish Redkar !

The Behavioral Cohort API will let you create a new cohort. However, the API does not let you define parameters such as the screenshot you shared.

You can only upload the users by Amplitude ID or User ID:

curl -i --user "API_KEY:SECRET_KEY" -H "Content-Type: application/json" --data '
{"name":"Test Cohort","app_id":305689,"id_type":"BY_USER_ID","ids":["Eddie Gaona"],"owner":"datamonster@amplitude.com","published":true}
' https://amplitude.com/api/3/cohorts/upload

Above I am creating a new cohort and including the user with the User ID set to “Eddie Gaona”. There are not APIs currently that will let you create cohorts by parameters.

Userlevel 7
Badge +4

Thanks for the clarification @eddie.gaona ! 
So the above snippet mimics the “Import Cohort from File” functionality , correct? 

Userlevel 4
Badge +4

Hello @Saish Redkar ! 

Yes, the snippet would mimic the “Import Cohort from File” functionality. 

Reply