User Segments API

User Segments API

Info
Note: In this system, a "Cohort" is a group of users, similar to a "User Segment".

core_cohort_add_cohort_members

This function adds one or more users to a specified cohort.

Let's review the POST parameters for this function:

  1. Required Parameters:
    • The entire members object is required to identify the user and the cohort.
    • members[0][cohorttype][type]= string (Required: How to identify the cohort. Use 'id' for the numeric ID or 'idnumber' for the alphanumeric ID.)
    • members[0][cohorttype][value]= string (Required: The actual ID or idnumber of the cohort.)
    • members[0][usertype][type]= string (Required: How to identify the user. Use 'id' for the numeric user ID or 'username' for the alphanumeric username.)
    • members[0][usertype][value]= string (Required: The actual ID or username of the user.)

cURL Command Example (Adding a User to a Cohort):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_cohort_add_cohort_members" \
-d "members[0][cohorttype][type]=idnumber" \
-d "members[0][cohorttype][value]=FALL2025-ENG101" \
-d "members[0][usertype][type]=username" \
-d "members[0][usertype][value]=janedoe"



core_cohort_delete_cohort_members

This function removes one or more users from a specified cohort.

Let's review the POST parameters for this function:

  1. Required Parameters:
    • members[0][cohortid]= int (Required: The numeric ID of the cohort.)
    • members[0][userid]= int (Required: The numeric ID of the user to be removed.)

cURL Command Example (Removing a User from a Cohort):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_cohort_delete_cohort_members" \
-d "members[0][cohortid]=45" \
-d "members[0][userid]=123"



core_cohort_create_cohorts

This function creates one or more new cohorts.

Let's review the POST parameters for this function:

  1. Required Parameters:
    • cohorts[0][categorytype][type]= string (Required: The context for the cohort. Use 'system' for site-level.)
    • cohorts[0][categorytype][value]= string (Required: The value for the context. If type is 'system', this can be 0 or 1.)
    • cohorts[0][name]= string (Required: The name of the cohort.)
    • cohorts[0][idnumber]= string (Required: A unique alphanumeric ID for the cohort.)
  2. Optional Parameters:
    • cohorts[0][description]= string (Optional: A description for the cohort.)
    • cohorts[0][visible]= int (Optional: Set to 1 for visible, 0 for hidden. Defaults to 1.)

cURL Command Example (Creating a New Cohort):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_cohort_create_cohorts" \
-d "cohorts[0][categorytype][type]=system" \
-d "cohorts[0][categorytype][value]=1" \
-d "cohorts[0][name]=Faculty Members" \
-d "cohorts[0][idnumber]=FACULTY" \
-d "cohorts[0][description]=All official faculty staff"



core_cohort_delete_cohorts

This function deletes one or more cohorts based on their IDs.

Let's review the POST parameters for this function:

  1. Required Parameter:
    • cohortids[0]= int (Required: The numeric ID of the cohort to delete. Pass multiple to delete more than one.)

cURL Command Example (Deleting a Cohort):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_cohort_delete_cohorts" \
-d "cohortids[0]=45"



core_cohort_get_cohorts

This function retrieves information about one or more cohorts.

Let's review the POST parameters for this function:

  1. Optional Parameter:
    • cohortids[0]= int (Optional: The numeric ID of a cohort to retrieve. If omitted, the system may return all cohorts.)

cURL Command Example (Getting Specific Cohorts):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_cohort_get_cohorts" \
-d "cohortids[0]=45" \
-d "cohortids[1]=46"