Skip to main content
Docs

revokeInvitation()

Revokes an Invitation.

Revoking an invitation makes the invitation email link unusable. 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.

function revokeInvitation(invitationId: string): Promise<Invitation>
  • Name
    invitationId
    Type
    string
    Description

    The ID of the invitation to revoke.

Note

Using clerkClient varies based on the SDK you're using. Refer to the overview for usage details, including guidance on how to access the userId and other properties.

const invitationId = 'inv_123'

const response = await clerkClient.invitations.revokeInvitation(invitationId)
import { createClerkClient } from '@clerk/backend'

// Initialize clerkClient
const clerkClient = createClerkClient({
  secretKey: process.env.CLERK_SECRET_KEY,
})

export async function POST() {
  // Use the `revokeInvitation()` method to revoke the invitation
  const invitation = await clerkClient.invitations.revokeInvitation({
    invitationId: 'invitation_123',
  })

  return Response.json({ message: 'Invitation revoked', invitation })
}
app/api/example/route.ts
import { clerkClient } from '@clerk/nextjs/server'
import { NextResponse } from 'next/server'

export async function POST() {
  // Initialize clerkClient
  const client = await clerkClient()

  // Use the `revokeInvitation()` method to revoke the invitation
  const invitation = await client.invitations.revokeInvitation({
    invitationId: 'invitation_123',
  })

  return NextResponse.json({ message: 'Invitation revoked' })
}
src/api/example.ts
import type { APIRoute } from 'astro'
import { clerkClient } from '@clerk/astro/server'

export const POST: APIRoute = async (context) => {
  // Initialize clerkClient
  // Use the `revokeInvitation()` method to revoke the invitation
  await clerkClient(context).invitations.revokeInvitation({
    invitationId: 'invitation_123',
  })

  return new Response(JSON.stringify({ success: true }), { status: 200 })
}
public.ts
import { getAuth, clerkClient } from '@clerk/express'

app.post('/revokeInvitation', async (req, res) => {
  // Initialize clerkClient
  // Use the `revokeInvitation()` method to revoke the invitation
  await clerkClient.invitations.revokeInvitation({
    invitationId: 'invitation_123',
  })

  res.status(200).json({ success: true })
})
src/routes/example.ts
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
import { clerkClient } from '@clerk/fastify'

export const exampleRoutes = (fastify: FastifyInstance) => {
  fastify.post('/revokeInvitation', async (req: FastifyRequest, res: FastifyReply) => {
    // Initialize clerkClient
    // Use the `revokeInvitation()` method to revoke the invitation
    await clerkClient.invitations.revokeInvitation({
      invitationId: 'invitation_123',
    })

    res.status(200).json({ success: true })
  })
}
server/api/example.ts
import { clerkClient } from '@clerk/nuxt/server'

export default defineEventHandler(async (event) => {
  // Initialize clerkClient
  // Use the `revokeInvitation()` method to revoke the invitation
  await clerkClient(event).invitations.revokeInvitation({
    invitationId: 'invitation_123',
  })

  return { success: true }
})
app/routes/example.tsx
import { clerkClient } from '@clerk/react-router/server'
import type { Route } from './+types/example'
import { json, redirect } from 'react-router-dom'

export async function action({ request }: Route.ActionArgs) {
  const formData = await request.formData()
  const invitationId = formData.get('invitationId')

  await clerkClient.invitations.revokeInvitation({
    invitationId: invitationId,
  })

  return json({ success: true })
}
app/routes/api/example.tsx
import { json } from '@tanstack/react-start'
import { createFileRoute } from '@tanstack/react-router'
import { clerkClient } from '@clerk/tanstack-react-start/server'

export const ServerRoute = createFileRoute('/api/example')({
  server: {
    handlers: {
      POST: async () => {
        await clerkClient().invitations.revokeInvitation({
          invitationId: 'invitation_123',
        })

        return json({ success: true })
      },
    },
  },
})

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint POST/invitations/{invitation_id}/revoke. See the BAPI reference for more information.

Here's an example of making a request directly to the endpoint using cURL.

terminal
curl https://api.clerk.com/v1/invitations/<invitation_id>/revoke -X POST -H "Authorization:Bearer YOUR_SECRET_KEY" -H 'Content-Type:application/json'

Feedback

What did you think of this content?

Last updated on