Get API Key
Retrieves the current API key for a specific user by their User ID.
Endpoint
GET /v2/users/key/{id}
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | integer | Yes | The User ID whose API key to retrieve |
note
This operation requires NetworkAdmin or higher AuthLevel. Users may retrieve their own API key via Get Me and Generate API Key.
Response
Returns the API key string for the specified user.
{
"success": true,
"data": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Code Examples
- cURL
- C#
- Java
- Node.js
- Python
curl -X GET "https://rest.ecgrid.io/v2/users/key/$ID" \
-H "X-API-Key: $ECGRID_API_KEY"
// .NET 10 — Retrieve a user's API key using IHttpClientFactory
// Requires NetworkAdmin or higher auth level
public async Task<string?> GetApiKeyAsync(IHttpClientFactory httpClientFactory, int userId)
{
var http = httpClientFactory.CreateClient("ECGridRest");
var response = await http.GetAsync($"https://rest.ecgrid.io/v2/users/key/{userId}");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ApiResponse<string>>();
return result?.Data;
}
import java.net.URI;
import java.net.http.*;
String apiKey = System.getenv("ECGRID_API_KEY");
String id = "0"; // replace with actual id
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(String.format("https://rest.ecgrid.io/v2/users/key/%s", id)))
.header("X-API-Key", apiKey)
.GET()
.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/key/${id}`;
const response = await fetch(url, {
method: 'GET',
headers: { 'X-API-Key': apiKey },
});
const data = await response.json();
console.log(data);
import os, requests
api_key = os.environ["ECGRID_API_KEY"]
headers = {"X-API-Key": api_key}
id = 0 # replace with actual id
url = f"https://rest.ecgrid.io/v2/users/key/{id}"
response = requests.get(url, headers=headers)
response.raise_for_status()
print(response.json())
See Also
- Generate API Key — generate a new API key, invalidating the current one
- Get Me — retrieve your own user context and confirm which key is active
- Authentication — how to use API keys in requests