# Create User Invitation — Clerk

> 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…

- Key: `clerk-create-user-invitation`
- Type: Action (Write)
- Version: 0.0.3
- App: Clerk (`clerk`) — https://pipedream.com/apps/clerk.md
- This page (HTML): https://pipedream.com/apps/clerk/actions/create-user-invitation
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/clerk/actions/create-user-invitation/create-user-invitation.mjs

## Description

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. [See the documentation](https://clerk.com/docs/reference/backend-api/tag/Invitations#operation/CreateInvitation)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `emailAddress` | `string` | Yes | The email address the invitation will be sent to. |
| `publicMetadata` | `object` | No | Metadata that will be attached to the newly created invitation. The value of this property should be a well-formed JSON object. Once the user accepts the invitation and signs up, these metadata will end up in the user's public metadata. |
| `redirectUrl` | `string` | No | Optional URL which specifies where to redirect the user once they click the invitation link. This is only required if you have implemented a custom flow and you're not using Clerk Hosted Pages or Clerk Components. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "clerk",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "clerk-create-user-invitation",
  arguments: {
    emailAddress: "Email Address",
    publicMetadata: "Public Metadata",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "clerk-create-user-invitation",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    clerk: { authProvisionId: "apn_xxxxxxx" },
    emailAddress: "Email Address",
    publicMetadata: "Public Metadata",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "clerk-create-user-invitation",
    "configured_props": {
      "clerk": { "authProvisionId": "apn_xxxxxxx" },
      "emailAddress": "Email Address",
      "publicMetadata": "Public Metadata"
    }
  }'
```

---

- App: https://pipedream.com/apps/clerk.md · All apps: https://pipedream.com/apps
