Retrieving user data

You can retrieve data about users through cURL or one of the SDKs. Each provides a way to filter the list of users by data associated with the user, such as username or UUID, or other properties in the user entity.

See User entity properties for a list of the system-defined properties for user entities. In addition, you can create user properties specific to your application.

Request Syntax

Request URI

Parameters

Parameter

Description

uuid | org_id

Organization UUID or organization name

uuid | app_id

Application UUID or application name

uuid | uuid | username | email_address

User UUID, username, or email address. The alias /users/me can be used in place of the current user’s uuid, username, or email address. Note: The /users/me endpoint is accessible only if you provide an access token with the request (see Authenticating users and application clients). If you make an anonymous ("guest") call, the system will not be able to determine which user to return as /users/me.

Note: The username can contain any combination of characters, including those that represent letters, numbers, and symbols.

Example

Request

# Get a user by username.
curl -X GET "https://api.usergrid.com/my-org/my-app/users/jane.doe"
# Get a user by UUID.
curl -X GET "https://api.usergrid.com/my-org/my-app/users/a407b1e7-58e8-11e1-ac46-22000a1c5a67e"
# Get a user by email.
curl -X GET "https://api.usergrid.com/my-org/my-app/users/jane.doe@gmail.com"
# Get user data filtering by their city property value.
curl -X GET "https://api.usergrid.com/my-org/my-app/users?ql=select%20*%20where%20adr.city%3D'Chicago'"

Example

// Create a query string that narrows the results to
// the users you want -- here, those whose city value is "Chicago".
String ql = "adr.city='Chicago'";
// Call a data client method to retrieve the user data
// asynchronously. Handle the result with methods of the
// callback object created here.
dataClient.queryUsersAsync(ql, new QueryResultsCallback() {
@Override
public void onException(Exception e) {
// Log an error.
}
// Handle the result of the query here.
@Override
public void onResponse(Query query) {
if (query != null) {
ApiResponse response = query.getResponse();
if (response != null) {
// Get the list of users from the query response.
List users = response.getEntities();
// Do something with the user data here, such
// as bind it to some user interface.
} else {
// Display and/or log an error.
}
}
}
@Override
public void onQueryResults(Query query) {
// This method is currently not implemented.
}
});

This is the Usergrid.Collection method for getting user data from the data store. This method assumes a Collection instance that has been created with a "users" collection type. (Usergrid is the open source project on which these features are based.)

Asynchronous

collection.fetch (callback)

Parameters

Part

Description

callback

A handler to receive the response from an asynchronous call.

collection

A Usergrid.Collection instance.

Example

// Create a collection instance to keep the users in.
// apigeeClient is an instance of Apigee.Client. This
// expression uses a query to narrow the results to
// only those users whose city value is "Chicago".
// To get all users regardless of city, you'd not
// include a qs property when creating the collection.
var users = new Apigee.Collection({
"client":apigeeClient,
"type":"users",
"qs": {
"ql":"adr.city = 'Chicago'"
}
});
// Fetch the users from the database.
users.fetch(
// Called if the fetch succeeded.
function () {
if (users.hasNextEntity()){
// Do something with the received data.
} else {
// Do something if there aren't any users in that city.
}
},
// Called if the attempt to get users failed.
function () {
client.logError({tag:"getUsers",
logMessage:"Unable to retrieve users."})
}
);