User API

User API

core_user_create_users

We advise the use of a developer to help you setup your API connection. This example shows how to create new users.

Let's review the POST parameters for this function:

  1. Required Parameters:
    • users[0][username]= string (Required: The user's unique username)
    • users[0][firstname]= string (Required: The user's first name)
    • users[0][lastname]= string (Required: The user's last name)
    • users[0][email]= string (Required: The user's unique email address)
    • users[0][password]= string (Required: The user's password. Must be provided if createpassword is 0)
  2. Optional Parameters:
    • users[0][auth]= string (Optional: Auth plugin. Defaults to "manual")
    • users[0][idnumber]= string (Optional: An official ID number for the user)
    • users[0][lang]= string (Optional: Language code. Defaults to "en")
    • users[0][city]= string (Optional: The user's home city)
    • users[0][country]= string (Optional: A two-letter country code, e.g., "US" or "ZA")
    • users[0][description]= string (Optional: A profile description for the user)
    • users[0][customfields][0][type]= string (Optional: The 'shortname' of the custom profile field)
    • users[0][customfields][0][value]= string (Optional: The value for the custom field)

cURL Command Example (Creating a User):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_user_create_users" \
-d "users[0][username]=janedoe" \
-d "users[0][password]=StrongPassword456!" \
-d "users[0][firstname]=Jane" \
-d "users[0][lastname]=Doe" \
-d "users[0][email]=janedoe@yourdomain.com" \
-d "users[0][city]=Cape Town" \
-d "users[0][country]=ZA"



core_user_update_users

This function allows you to modify the details of an existing user. You must specify the user's ID.

Let's review the POST parameters for this function:

  1. Required Parameter:
    • users[0][id]= int (Required: The ID of the user you want to update)
  2. Optional Parameters (Include only the fields you wish to change):
    • users[0][username]= string (Optional: A new unique username)
    • users[0][firstname]= string (Optional: A new first name)
    • users[0][lastname]= string (Optional: A new last name)
    • users[0][email]= string (Optional: A new unique email address)
    • users[0][suspended]= int (Optional: Set to 1 to suspend the user, 0 to unsuspend)
    • users[0][city]= string (Optional: A new city)
    • users[0][department]= string (Optional: A new department)

cURL Command Example (Updating a User):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_user_update_users" \
-d "users[0][id]=123" \
-d "users[0][city]=Johannesburg" \
-d "users[0][suspended]=1"



core_user_get_users

This function is used to search for and retrieve user details based on specific criteria.

Let's review the POST parameters for this function:

  1. Required Parameter Structure:
    • The criteria parameter is required and contains a key and a value.
    • criteria[0][key]= string (Required: The field to search on. See valid keys below.)
    • criteria[0][value]= string (Required: The value to search for.)
  2. Valid Keys for Criteria:
    • id (Search by user ID)
    • username (Search by exact username)
    • email (Search by exact email address)
    • idnumber (Search by ID number)
    • lastname (Search by last name)
    • firstname (Search by first name)

cURL Command Example (Getting a User by Email):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_user_get_users" \
-d "criteria[0][key]=email" \
-d "criteria[0][value]=janedoe@yourdomain.com"