> ## Documentation Index
> Fetch the complete documentation index at: https://developers.factify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Invite Organization Member

> Send invitations to add members to your organization.

## Overview

Invitations allow you to add members to your organization. When you create an invitation, the recipient receives an email with a link to accept. Invitations expire after 7 days.

## Prerequisites

* An organization ID (find yours in the [Developer Dashboard](https://platform.factify.com))
* A valid API key with permission to manage organization members

## Code Example

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Factify } from "@factify/sdk";

  const factify = new Factify({ bearerAuth: process.env.FACTIFY_KEY });

  async function inviteMember(organizationId: string, email: string) {
    const result = await factify.organizations.invites.create({
      organizationId,
      body: {
        email,
        message: "Welcome to the team!" // Optional custom message
      }
    });

    console.log(`Invitation sent: ${result.invite?.id}`);
    return result.invite;
  }

  inviteMember(
    "org_01h2xcejqtf2nbrexx3vqjhp41",
    "pam.beesly@dundermifflin.com"
  );
  ```

  ```python Python theme={null}
  import os
  from factify import Factify

  factify = Factify(bearer_auth=os.environ["FACTIFY_KEY"])

  def invite_member(organization_id: str, email: str):
      response = factify.organizations.invites.create(
          organization_id=organization_id,
          email=email,
          message="Welcome to the team!"  # Optional custom message
      )

      print(f"Invitation sent: {response.result.invite.id}")
      return response.result.invite

  invite_member(
      "org_01h2xcejqtf2nbrexx3vqjhp41",
      "pam.beesly@dundermifflin.com"
  )
  ```
</CodeGroup>

## Response

```json theme={null}
{
  "invite": {
    "id": "inv_01h2xcejqtf2nbrexx3vqjhp42",
    "organization_id": "org_01h2xcejqtf2nbrexx3vqjhp41",
    "email": "pam.beesly@dundermifflin.com",
    "status": "ORGANIZATION_INVITE_STATUS_PENDING",
    "sender": {
      "id": "user_01h2xcejqtf2nbrexx3vqjhp40",
      "type": "USER_TYPE_USER_ACCOUNT",
      "name": "John Doe"
    },
    "created_at": "2024-01-15T09:30:00Z",
    "expires_at": "2024-01-22T09:30:00Z",
    "message": "Welcome to the team!"
  }
}
```

## Options

| Parameter        | Type   | Description                                    |
| ---------------- | ------ | ---------------------------------------------- |
| `organizationId` | string | Required. The organization to invite to        |
| `email`          | string | Required. Email address of the recipient       |
| `message`        | string | Optional. Custom message (max 2000 bytes)      |
| `idempotencyKey` | string | Optional. Client-provided key for safe retries |

## Idempotency

If you include an `idempotency_key`, duplicate requests within 24 hours return the original response without resending the email. This is useful for retry logic.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const result = await factify.organizations.invites.create({
    organizationId: "org_01h2xcejqtf2nbrexx3vqjhp41",
    body: {
      email: "pam.beesly@dundermifflin.com",
      idempotencyKey: "my-unique-request-id-123"
    }
  });
  ```

  ```python Python theme={null}
  response = factify.organizations.invites.create(
      organization_id="org_01h2xcejqtf2nbrexx3vqjhp41",
      email="pam.beesly@dundermifflin.com",
      idempotency_key="my-unique-request-id-123"
  )
  ```
</CodeGroup>

## Listing Invitations

Check pending invitations for your organization:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const invites = await factify.organizations.invites.list({
    organizationId: "org_01h2xcejqtf2nbrexx3vqjhp41",
    status: ["ORGANIZATION_INVITE_STATUS_PENDING"]
  });

  for await (const page of invites) {
    console.log(page.items);
  }
  ```

  ```python Python theme={null}
  invites = factify.organizations.invites.list(
      organization_id="org_01h2xcejqtf2nbrexx3vqjhp41",
      status=["ORGANIZATION_INVITE_STATUS_PENDING"]
  )

  for page in invites:
      print(page.result.items)
  ```
</CodeGroup>

## Revoking an Invitation

Cancel a pending invitation:

<CodeGroup>
  ```typescript TypeScript theme={null}
  await factify.organizations.invites.revoke({
    organizationId: "org_01h2xcejqtf2nbrexx3vqjhp41",
    inviteId: "inv_01h2xcejqtf2nbrexx3vqjhp42"
  });
  ```

  ```python Python theme={null}
  factify.organizations.invites.revoke(
      organization_id="org_01h2xcejqtf2nbrexx3vqjhp41",
      invite_id="inv_01h2xcejqtf2nbrexx3vqjhp42"
  )
  ```
</CodeGroup>

## Error Handling

| Error                 | Cause                            | Solution                                            |
| --------------------- | -------------------------------- | --------------------------------------------------- |
| `FAILED_PRECONDITION` | Email belongs to existing member | User is already in the organization                 |
| `PERMISSION_DENIED`   | Insufficient permissions         | Ensure your account can manage organization members |
| `NOT_FOUND`           | Invalid organization ID          | Verify the organization exists                      |

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/guides/authentication">
    Learn about API key management
  </Card>

  <Card title="Organizations" icon="building" href="/api-reference/organizations">
    Manage organization settings
  </Card>
</CardGroup>
