Logout
Invalidate the current Bearer token or API session, ending the authenticated session immediately.
Endpoint
POST /v2/auth/logout
Request Body
No request body is required. The session is identified from the Authorization or X-API-Key header on the request.
Response
Returns a success confirmation. After a successful logout, the token or session used to make this call is no longer valid.
{
"success": true,
"data": null,
"errorCode": "",
"message": "Session terminated."
}
caution
After calling logout, any subsequent requests using the same token will receive a 401 Unauthorized response. If you are using API Key authentication, logout terminates the current session but does not revoke the key itself.
Code Examples
- cURL
- C#
- Java
- Node.js
- Python
curl -X POST "https://rest.ecgrid.io/v2/auth/logout" \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "success": true, "data": null, "errorCode": "", "message": "Session terminated." }'
// .NET 10 — Logout and clear the authorization header
using System.Net.Http.Json;
/// <summary>
/// Logs out the current session and clears the client's authorization header.
/// </summary>
async Task LogoutAsync(HttpClient httpClient)
{
var response = await httpClient.PostAsync(
"https://rest.ecgrid.io/v2/auth/logout",
content: null);
response.EnsureSuccessStatusCode();
// Clear the stored token so it cannot be reused accidentally
httpClient.DefaultRequestHeaders.Authorization = null;
}
import java.net.URI;
import java.net.http.*;
String apiKey = System.getenv("ECGRID_API_KEY");
String body = "{ \"success\": true, \"data\": null, \"errorCode\": \"\", \"message\": \"Session terminated.\" }";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://rest.ecgrid.io/v2/auth/logout"))
.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/auth/logout';
const response = await fetch(url, {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json',
},
body: JSON.stringify({ "success": true, "data": null, "errorCode": "", "message": "Session terminated." }),
});
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/auth/logout"
response = requests.post(
url,
json={ "success": true, "data": null, "errorCode": "", "message": "Session terminated." },
headers=headers,
)
response.raise_for_status()
print(response.json())
See Also
- Login — start a new session
- Refresh Token — extend an active session before logout
- Session — inspect the current session before logging out