Managing Users
The Qualtrics APIs for managing users allow you to get information about a specific user, list all users, create a new user, update a user's attributes, and delete a user.
The following APIs are discussed:
Get User
The Get User API allows you to retrieve information about a user. User information can be edited in the Admin area of the Qualtrics user interface. See Creating and Managing Users for more information. See Finding your Qualtrics IDs for information on how to retrieve IDs.
Brand Administrator
The Get User API may be called on your own user Id, but to retrieve information about other users you must be a brand administrator.
Code and Qualtrics Support
Our support team does not offer assistance or consultation on custom coding, but you can always try asking our community of dedicated users. If you’d like to know more about our custom coding services you can commission, please contact your Qualtrics Account Executive.
The following example shows how to request user info for the specified user:
# Get User
import requests
# Setting user parameters
apiToken = "YOUR API TOKEN" # 1
dataCenter = "YOUR DATACENTER" # 2
userId = "USER ID TO LOOK UP" # 3
baseUrl = "https://{0}.qualtrics.com/API/v3/users/{1}".format(dataCenter, userId)
headers = {
"x-api-token": apiToken,
}
response = requests.get(baseUrl, headers=headers)
print(response.text)
The response JSON object contains the following members that describe the user:
| Member | Type | Description |
|---|---|---|
| accountCreationDate | String | The date and time that the account was created. Dates and times are expressed in ISO 8601 format (see ISO 8601). |
| accountExpirationDate | String | The date the account expires. Dates and times are expressed in ISO 8601 format (see ISO 8601). |
| divisionId | String | The user's division ID or null if there is no division ID. |
| String | The user's email address. | |
| firstName | String | The user's first name or given name. |
| id | String | The user ID. |
| language | String | The user's default language. |
| lastLoginDate | String | The date and time the user last logged into the user interface. Dates and times are expressed in ISO 8601 format (see ISO 8601). |
| lastName | String | The user's last name or surname. |
| organizationId | String | The user's organization ID. See the instructions on Finding Your Qualtrics ID to locate your organizationId in your Qualtrics Account Settings. |
If you do not have permissions to access to the user's data, you will receive a 401 response as shown below:
{
"meta": {
"error": {
"errorCode": "UJC_3",
"errorMessage": "You do not have read access on this user data."
},
"httpStatus": "401 - Unauthorized",
"requestId": null
}
}
List Users
The List Users API returns information about the user collection on your site. You need to be a brand administrator to retrieve user information.
The following sample shows how to retrieve the user collection:
# List Users
import requests
#Setting user Parameters
apiToken = "YOUR API TOKEN"
dataCenter = 'YOUR DATACENTER'
baseUrl = "https://{0}.qualtrics.com/API/v3/users".format(dataCenter)
headers = {
"x-api-token": apiToken,
}
response = requests.get(baseUrl, headers=headers)
print(response.text)
The returned response contains an array of the users in the data center as the following JSON object shows:
{
"meta": {
"httpStatus": "200 - OK",
"requestId": "b84c6dd7-9223-4003-9744-ed72f3ea7b83"
},
"result": {
"elements": [
{
"accountStatus": "active",
"divisionId": null,
"email": "person@example.com",
"firstName": "John",
"id": "UR_1234567890",
"lastName": "Smith",
"userType": "UT_12345678",
"username": "person@example.com"
},
{
"accountStatus": "active",
"divisionId": null,
"email": "person2@example.com",
"firstName": "Jane",
"id": "UR_9876543210",
"lastName": "Doe",
"userType": "UT_76890123",
"username": "person2@example.com"
},
],
"nextPage": null
}
}
The following sample shows how to make multiple requests to retrieve all users instead of just the first 100.
import requests
# Setting user Parameters
apiToken = "YOUR API TOKEN"
dataCenter = 'YOUR DATACENTER'
baseUrl = "https://{0}.qualtrics.com/API/v3/users".format(dataCenter)
headers = {
"x-api-token": apiToken,
}
users = []
while baseUrl is not None:
response = requests.get(baseUrl, headers=headers)
baseUrl = response.json()['result']['nextPage']
users += response.json()['result']['elements']
for user in users:
print(user)
See the table under Get User for more information about the attributes returned for each user.
Create User
The Create User API allows you to create a new user with the specified attributes. The parameters you are required to specify include:
- Username
- Password
- First name
- Last name
- User type (see User Types for more information about creating and using user types.)
- Email address
- Language (see Language Codes for available language codes.)
Optional parameters include:
- Division ID
- Account expiration date
The table under Get User has more information about these attributes.
# Create User
import requests
# Setting user Parameters
apiToken = "YOUR API TOKEN" # 1
dataCenter = "YOUR DATACENTER" # 2
baseUrl = "https://{0}.qualtrics.com/API/v3/users".format(dataCenter)
headers = {
"x-api-token": apiToken,
"Content-Type": "application/json"
}
data = { "username": "person@example.com",
"password": "aPassword",
"firstName": "John",
"lastName": "Smith",
"userType": "UT_123456789",
"email": "person@example.com",
"language": "en",
}
response = requests.post(baseUrl, json=data, headers=headers)
print(response.text)
The response object includes the new user's ID:
{
"meta": {
"httpStatus": "200 - OK",
"requestId": "d121c1a0-c86e-4bba-8594-ddfcee1569a1"
},
"result": {
"id": "UR_1234567890"
}
}
Update User
The Update User API lets you change certain user attributes. All attributes are optional and include:
- User name
- First name
- Last name
- User type
- Division ID
- Status (active, disabled, notVerified)
- Language
- Permissions
- Account expiration date
The only parameter that is required is the user ID, and it is specified in the URL.
The following example shows how to change a user's first name:
# Update User
import requests
# Setting user Parameters
apiToken = "YOUR API TOKEN" # 1
dataCenter = "YOUR DATACENTER" # 2
userId = "UR_1234567890"
baseUrl = "https://{0}.qualtrics.com/API/v3/users/{1}".format(dataCenter, userId)
headers = {
"x-api-token": apiToken,
"Content-Type": "application/json"
}
data = {
"firstName": "Joe",
}
response = requests.put(baseUrl, json=data, headers=headers)
print(response.text)
A successful update results in a 200 status code.
Delete User
The Delete User API deletes the specified user, but it requires brand administrator permissions.
# Delete User
import requests
# Setting user Parameters
apiToken = "YOUR API TOKEN" # 1
dataCenter = "YOUR DATACENTER" # 2
userId = "UR_1234567890"
baseUrl = "https://{0}.qualtrics.com/API/v3/users/{1}".format(dataCenter, userId)
headers = {
"x-api-token": apiToken,
}
response = requests.delete(baseUrl, headers=headers)
print(response.text)
A successful delete results in a 200 status code.