GenerateAPIKey
Generates a new API key for a user, replacing any existing key.
:::caution Established API The SOAP API is in maintenance mode. For new integrations use the REST equivalent. :::
:::caution Key Replacement Generating a new key immediately invalidates the previous key for this user. Update any integrations that use the old key before or immediately after calling this method. :::
Method Signature
string GenerateAPIKey(string SessionID, int UserID)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
SessionID | string | Yes | Active session token from Login() |
UserID | int | Yes | ID of the user for whom to generate a new API key |
Response Object — string
Returns the newly generated API key string.
<!-- Example response XML -->
<GenerateAPIKeyResult>mnp456qrs789tuv012wxy345zab678cd</GenerateAPIKeyResult>
Code Examples
- C#
- Java
- Node.js
- Python
// .NET 10 — dotnet-svcutil generated proxy
// Generate a new API key — the previous key is immediately invalidated
string newKey = await client.GenerateAPIKeyAsync(sessionID, userId);
Console.WriteLine($"New API key generated for user {userId}:");
Console.WriteLine(newKey);
Console.WriteLine("Update all integrations using this user's previous key.");
// JAX-WS generated client
// wsimport -s src https://os.ecgrid.io/v4.1/prod/ECGridOS.asmx?WSDL
ECGridOS service = new ECGridOS();
ECGridOSPortType port = service.getECGridOSPort();
var result = port.GenerateAPIKey(sessionID /*, additional params */);
System.out.println(result);
// npm install soap
import soap from 'soap';
const WSDL = 'https://os.ecgrid.io/v4.1/prod/ECGridOS.asmx?WSDL';
const client = await soap.createClientAsync(WSDL);
const [result] = await client.GenerateAPIKeyAsync({
SessionID: sessionId,
// additional params
});
console.log(result);
# pip install zeep
from zeep import Client
WSDL = 'https://os.ecgrid.io/v4.1/prod/ECGridOS.asmx?WSDL'
client = Client(WSDL)
result = client.service.GenerateAPIKey(
SessionID=session_id,
# additional params
)
print(result)
REST Equivalent
See Generate API Key — POST /v2/users/key-generate/{id}.