(invitations())
Invitations allow you to invite someone to sign up to your application, via email. https://clerk.com/docs/authentication/invitations
Creates a new invitation for the given email address and sends the invitation email. Keep in mind that you cannot create an invitation if there is already one for the given email address. Also, trying to create an invitation for an email address that already exists in your application will result to an error.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.CreateInvitationRequestBody;
import com.clerk.backend_api.models.operations.CreateInvitationResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
CreateInvitationRequestBody req = CreateInvitationRequestBody.builder()
.emailAddress("[email protected]")
.build();
CreateInvitationResponse res = sdk.invitations().create()
.request(req)
.call();
if (res.invitation().isPresent()) {
// handle response
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
request |
CreateInvitationRequestBody | ✔️ | The request object to use for the request. |
Error Type | Status Code | Content Type |
---|---|---|
models/errors/ClerkErrors | 400, 422 | application/json |
models/errors/SDKError | 4XX, 5XX | */* |
Returns all non-revoked invitations for your application, sorted by creation date
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.operations.ListInvitationsQueryParamStatus;
import com.clerk.backend_api.models.operations.ListInvitationsResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
ListInvitationsResponse res = sdk.invitations().list()
.limit(10L)
.offset(0L)
.status(ListInvitationsQueryParamStatus.EXPIRED)
.call();
if (res.invitationList().isPresent()) {
// handle response
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
limit |
Optional<Long> | ➖ | Applies a limit to the number of results returned. Can be used for paginating the results together with offset . |
offset |
Optional<Long> | ➖ | Skip the first offset results when paginating.Needs to be an integer greater or equal to zero. To be used in conjunction with limit . |
status |
Optional<ListInvitationsQueryParamStatus> | ➖ | Filter invitations based on their status |
Error Type | Status Code | Content Type |
---|---|---|
models/errors/SDKError | 4XX, 5XX | */* |
Revokes the given invitation. Revoking an invitation will prevent the user from using the invitation link that was sent to them. However, it doesn't prevent the user from signing up if they follow the sign up flow. Only active (i.e. non-revoked) invitations can be revoked.
package hello.world;
import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.errors.ClerkErrors;
import com.clerk.backend_api.models.operations.RevokeInvitationResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ClerkErrors, Exception {
Clerk sdk = Clerk.builder()
.bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
.build();
RevokeInvitationResponse res = sdk.invitations().revoke()
.invitationId("<id>")
.call();
if (res.invitationRevoked().isPresent()) {
// handle response
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
invitationId |
String | ✔️ | The ID of the invitation to be revoked |
Error Type | Status Code | Content Type |
---|---|---|
models/errors/ClerkErrors | 400, 404 | application/json |
models/errors/SDKError | 4XX, 5XX | */* |