---
displayed_sidebar: jsClientSidebar
slug: /references/js-client/AdminInvitesResource
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# AdminInvitesResource

This class is used to send requests to [Admin Invite API Routes](https://docs.medusajs.com/api/admin#invites). All its method
are available in the JS Client under the `medusa.admin.invites` property.

All methods in this class require [user authentication](js_client.AdminAuthResource.mdx#createsession).

An admin can invite new users to manage their team. This would allow new users to authenticate as admins and perform admin functionalities.

Related Guide: [How to manage invites](https://docs.medusajs.com/modules/users/admin/manage-invites).

## Methods

### accept

Accept an Invite. This will also delete the invite and create a new user that can log in and perform admin functionalities. 
The user will have the email associated with the invite, and the password provided in the `payload` parameter.

#### Example

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.invites.accept({
  token,
  user: {
    first_name: "Brigitte",
    last_name: "Collier",
    password: "supersecret"
  }
})
.then(() => {
  // successful
})
.catch(() => {
  // an error occurred
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "payload",
    "type": "[AdminPostInvitesInviteAcceptReq](../../medusa/classes/medusa.AdminPostInvitesInviteAcceptReq.mdx)",
    "description": "The user accepting the invite.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "token",
        "type": "`string`",
        "description": "The token of the invite to accept. This is a unique token generated when the invite was created or resent.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "user",
        "type": "[AdminPostInvitesInviteAcceptUserReq](../../medusa/classes/medusa.AdminPostInvitesInviteAcceptUserReq.mdx)",
        "description": "The details of the user to create.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "first_name",
            "type": "`string`",
            "description": "The invite's first name.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "last_name",
            "type": "`string`",
            "description": "The invite's last name.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "password",
            "type": "`string`",
            "description": "The invite's password",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "`ResponsePromise`",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves when the invite is accepted successfully.",
    "expandable": false,
    "children": []
  }
]} />

___

### create

Create an invite. This will generate a token associated with the invite and trigger an `invite.created` event. If you have a Notification Provider installed that handles this
event, a notification should be sent to the email associated with the invite to allow them to accept the invite.

#### Example

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.invites.create({
  user: "user@example.com",
  role: "admin"
})
.then(() => {
  // successful
})
.catch(() => {
  // an error occurred
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "payload",
    "type": "`AdminPostInvitesPayload`",
    "description": "The invite to be created.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "`ResponsePromise`",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves when the invite is created successfully.",
    "expandable": false,
    "children": []
  }
]} />

___

### delete

Delete an invite. Only invites that weren't accepted can be deleted.

#### Example

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.invites.delete(inviteId)
.then(({ id, object, deleted }) => {
  console.log(id);
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "The invite's ID.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;DeleteResponse&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the deletion operation's details.",
    "expandable": false,
    "children": [
      {
        "name": "deleted",
        "type": "`boolean`",
        "description": "Whether the item was deleted successfully.",
        "optional": false,
        "defaultValue": "true",
        "expandable": false,
        "children": []
      },
      {
        "name": "id",
        "type": "`string`",
        "description": "The ID of the deleted item.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "object",
        "type": "`string`",
        "description": "The type of the deleted item.",
        "optional": false,
        "defaultValue": "product-collection",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

___

### list

Retrieve a list of invites.

#### Example

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.invites.list()
.then(({ invites }) => {
  console.log(invites.length);
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;AdminListInvitesRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the list of invites.",
    "expandable": false,
    "children": [
      {
        "name": "invites",
        "type": "[Invite](../../entities/classes/entities.Invite.mdx)[]",
        "description": "An array of invites",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "accepted",
            "type": "`boolean`",
            "description": "Whether the invite was accepted or not.",
            "optional": false,
            "defaultValue": "false",
            "expandable": false,
            "children": []
          },
          {
            "name": "created_at",
            "type": "`Date`",
            "description": "The date with timezone at which the resource was created.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "deleted_at",
            "type": "`null` \\| `Date`",
            "description": "The date with timezone at which the resource was deleted.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "expires_at",
            "type": "`Date`",
            "description": "The date the invite expires at.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "id",
            "type": "`string`",
            "description": "The invite's ID",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "metadata",
            "type": "`Record<string, unknown>`",
            "description": "An optional key-value map with additional details",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "role",
            "type": "[UserRoles](../../entities/enums/entities.UserRoles.mdx)",
            "description": "The user's role. These roles don't change the privileges of the user.",
            "optional": false,
            "defaultValue": "member",
            "expandable": false,
            "children": [
              {
                "name": "ADMIN",
                "type": "`\"admin\"`",
                "description": "The user is an admin.",
                "optional": true,
                "defaultValue": "",
                "expandable": false,
                "children": []
              },
              {
                "name": "DEVELOPER",
                "type": "`\"developer\"`",
                "description": "The user is a developer.",
                "optional": true,
                "defaultValue": "",
                "expandable": false,
                "children": []
              },
              {
                "name": "MEMBER",
                "type": "`\"member\"`",
                "description": "The user is a team member.",
                "optional": true,
                "defaultValue": "",
                "expandable": false,
                "children": []
              }
            ]
          },
          {
            "name": "token",
            "type": "`string`",
            "description": "The token used to accept the invite.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "updated_at",
            "type": "`Date`",
            "description": "The date with timezone at which the resource was updated.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "user_email",
            "type": "`string`",
            "description": "The email of the user being invited.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />

___

### resend

Resend an invite. This renews the expiry date by seven days and generates a new token for the invite. It also triggers the `invite.created` event, 
so if you have a Notification Provider installed that handles this event, a notification should be sent to the email associated with the 
invite to allow them to accept the invite.

#### Example

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.invites.resend(inviteId)
.then(() => {
  // successful
})
.catch(() => {
  // an error occurred
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "The invite's ID.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "`ResponsePromise`",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves when the invite is resent successfully.",
    "expandable": false,
    "children": []
  }
]} />
