Get User by Name
Searches for users matching a given login name and returns all matching UserIDInfo records.
Endpoint
POST /v2/users/by-name
Request Body
| Field | Type | Required | Constraints | Description |
|---|---|---|---|---|
login | string | Yes | — | The login name to search for |
{
"login": "jsmith"
}
Response
Returns an array of UserIDInfo objects matching the provided login name. Multiple results may be returned if the same login exists across different networks.
{
"success": true,
"data": [
{
"userId": 1042,
"login": "jsmith",
"email": "jsmith@example.com",
"firstName": "John",
"lastName": "Smith",
"networkId": 1,
"mailboxId": 101,
"authLevel": "MailboxAdmin",
"status": "Active",
"created": "2024-03-15T10:22:00Z"
}
]
}
Code Examples
- cURL
- C#
- Java
- Node.js
- Python
curl -X POST "https://rest.ecgrid.io/v2/users/by-name" \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "login": "jsmith" }'
// .NET 10 — Find users by login name using IHttpClientFactory
public async Task<List<UserIdInfo>?> GetUsersByNameAsync(
IHttpClientFactory httpClientFactory,
string login)
{
var http = httpClientFactory.CreateClient("ECGridRest");
var requestBody = new { login };
var response = await http.PostAsJsonAsync(
"https://rest.ecgrid.io/v2/users/by-name",
requestBody);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ApiResponse<List<UserIdInfo>>>();
return result?.Data;
}
import java.net.URI;
import java.net.http.*;
String apiKey = System.getenv("ECGRID_API_KEY");
String body = "{ \"login\": \"jsmith\" }";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://rest.ecgrid.io/v2/users/by-name"))
.header("X-API-Key", apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
const apiKey = process.env.ECGRID_API_KEY;
const url = 'https://rest.ecgrid.io/v2/users/by-name';
const response = await fetch(url, {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
body: JSON.stringify({ "login": "jsmith" }),
});
const data = await response.json();
console.log(data);
import os, requests
api_key = os.environ["ECGRID_API_KEY"]
headers = {"X-API-Key": api_key}
url = "https://rest.ecgrid.io/v2/users/by-name"
response = requests.post(
url,
json={ "login": "jsmith" },
headers=headers,
)
response.raise_for_status()
print(response.json())
See Also
- Get User — retrieve a user by their numeric User ID
- List Users — paginated search with filters for network, mailbox, and auth level