Returns a list of sessions matching the provided criteria.
The sessions are returned sorted by creation date, with the newest sessions appearing first.
Note: This endpoint does not return all sessions that have ever existed. Old and inactive sessions are periodically cleaned up and will not be included in the results.
Deprecation Notice (2024-01-01): All parameters were initially considered optional, however
moving forward at least one of client_id or user_id parameters should be provided.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.GetSessionListRequest;
import com.clerk.backend_api.models.operations.GetSessionListResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
GetSessionListRequest req = GetSessionListRequest.builder()
.build();
GetSessionListResponse res = sdk.sessions().list()
.request(req)
.call();
if (res.sessionList().isPresent()) {
System.out.println(res.sessionList().get());
}
}
}
| Parameter |
Type |
Required |
Description |
request |
GetSessionListRequest |
✔️ |
The request object to use for the request. |
GetSessionListResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
400, 401, 422 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |
Create a new active session for the provided user ID.
This operation is intended only for use in testing, and is not available for production instances. If you are looking to generate a user session from the backend,
we recommend using the Sign-in Tokens resource instead.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.CreateSessionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
CreateSessionResponse res = sdk.sessions().create()
.call();
if (res.session().isPresent()) {
System.out.println(res.session().get());
}
}
}
CreateSessionResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
400, 401, 404, 422 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |
Retrieve the details of a session
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.GetSessionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
GetSessionResponse res = sdk.sessions().get()
.sessionId("<id>")
.call();
if (res.session().isPresent()) {
System.out.println(res.session().get());
}
}
}
| Parameter |
Type |
Required |
Description |
sessionId |
String |
✔️ |
The ID of the session |
GetSessionResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
400, 401, 404 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |
Refreshes a session by creating a new session token. A 401 is returned when there
are validation errors, which signals the SDKs to fall back to the handshake flow.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.components.*;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.RefreshSessionResponse;
import java.lang.Exception;
import java.lang.Object;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
RefreshSessionResponse res = sdk.sessions().refresh()
.sessionId("<id>")
.call();
if (res.sessionRefresh().isPresent()) {
SessionRefresh unionValue = res.sessionRefresh().get();
Object raw = unionValue.value();
if (raw instanceof Token) {
Token tokenValue = (Token) raw;
// Handle token variant
} else if (raw instanceof Cookies) {
Cookies cookiesValue = (Cookies) raw;
// Handle cookies variant
} else {
// Unknown or unsupported variant
}
}
}
}
RefreshSessionResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
400, 401 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |
Sets the status of a session as "revoked", which is an unauthenticated state.
In multi-session mode, a revoked session will still be returned along with its client object, however the user will need to sign in again.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.RevokeSessionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
RevokeSessionResponse res = sdk.sessions().revoke()
.sessionId("<id>")
.call();
if (res.session().isPresent()) {
System.out.println(res.session().get());
}
}
}
| Parameter |
Type |
Required |
Description |
sessionId |
String |
✔️ |
The ID of the session |
RevokeSessionResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
400, 401, 404 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |
Creates a session JSON Web Token (JWT) based on a session.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.CreateSessionTokenResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
CreateSessionTokenResponse res = sdk.sessions().createToken()
.sessionId("<id>")
.call();
if (res.object().isPresent()) {
System.out.println(res.object().get());
}
}
}
CreateSessionTokenResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
401, 404 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |
Creates a JSON Web Token (JWT) based on a session and a JWT Template name defined for your instance
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.CreateSessionTokenFromTemplateResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
CreateSessionTokenFromTemplateResponse res = sdk.sessions().createTokenFromTemplate()
.sessionId("<id>")
.templateName("<value>")
.call();
if (res.object().isPresent()) {
System.out.println(res.object().get());
}
}
}
CreateSessionTokenFromTemplateResponse
| Error Type |
Status Code |
Content Type |
| models/errors/ClerkErrors |
401, 404 |
application/json |
| models/errors/SDKError |
4XX, 5XX |
*/* |