(sessions())
Returns a list of all sessions.
The sessions are returned sorted by creation date, with the newest sessions appearing first.
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.SDKError;
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 Exception {
try {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
GetSessionListRequest req = GetSessionListRequest.builder()
.build();
GetSessionListResponse res = sdk.sessions().list()
.request(req)
.call();
if (res.sessionList().isPresent()) {
// handle response
}
} catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
// handle exception
throw e;
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameter |
Type |
Required |
Description |
request |
GetSessionListRequest |
✔️ |
The request object to use for the request. |
GetSessionListResponse
Error Object |
Status Code |
Content Type |
models/errors/ClerkErrors |
400,401,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.SDKError;
import com.clerk.backend_api.models.operations.GetSessionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
try {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
GetSessionResponse res = sdk.sessions().get()
.sessionId("<value>")
.call();
if (res.session().isPresent()) {
// handle response
}
} catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
// handle exception
throw e;
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameter |
Type |
Required |
Description |
sessionId |
String |
✔️ |
The ID of the session |
GetSessionResponse
Error Object |
Status Code |
Content Type |
models/errors/ClerkErrors |
400,401,404 |
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.SDKError;
import com.clerk.backend_api.models.operations.RevokeSessionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
try {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
RevokeSessionResponse res = sdk.sessions().revoke()
.sessionId("<value>")
.call();
if (res.session().isPresent()) {
// handle response
}
} catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
// handle exception
throw e;
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameter |
Type |
Required |
Description |
sessionId |
String |
✔️ |
The ID of the session |
RevokeSessionResponse
Error Object |
Status Code |
Content Type |
models/errors/ClerkErrors |
400,401,404 |
application/json |
models/errors/SDKError |
4xx-5xx |
*/* |
Returns the session if it is authenticated, otherwise returns an error.
WARNING: This endpoint is deprecated and will be removed in future versions. We strongly recommend switching to networkless verification using short-lived session tokens,
which is implemented transparently in all recent SDK versions (e.g. NodeJS SDK).
For more details on how networkless verification works, refer to our Session Tokens documentation.
⚠️ DEPRECATED: This will be removed in a future release, please migrate away from it as soon as possible.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.SDKError;
import com.clerk.backend_api.models.operations.VerifySessionRequestBody;
import com.clerk.backend_api.models.operations.VerifySessionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
try {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
VerifySessionResponse res = sdk.sessions().verify()
.sessionId("<value>")
.requestBody(VerifySessionRequestBody.builder()
.build())
.call();
if (res.session().isPresent()) {
// handle response
}
} catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
// handle exception
throw e;
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameter |
Type |
Required |
Description |
sessionId |
String |
✔️ |
The ID of the session |
requestBody |
Optional |
➖ |
Parameters. |
VerifySessionResponse
Error Object |
Status Code |
Content Type |
models/errors/ClerkErrors |
400,401,404,410 |
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.SDKError;
import com.clerk.backend_api.models.operations.CreateSessionTokenFromTemplateResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
try {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
CreateSessionTokenFromTemplateResponse res = sdk.sessions().createTokenFromTemplate()
.sessionId("<value>")
.templateName("<value>")
.call();
if (res.object().isPresent()) {
// handle response
}
} catch (com.clerk.backend_api.models.errors.ClerkErrors e) {
// handle exception
throw e;
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
Parameter |
Type |
Required |
Description |
sessionId |
String |
✔️ |
The ID of the session |
templateName |
String |
✔️ |
The name of the JWT Template defined in your instance (e.g. custom_hasura ). |
CreateSessionTokenFromTemplateResponse
Error Object |
Status Code |
Content Type |
models/errors/ClerkErrors |
401,404 |
application/json |
models/errors/SDKError |
4xx-5xx |
*/* |