Skip to main content
Skip to main content

AdminInvitesResource

This class is used to send requests to Admin Invite API Routes. All its method are available in the JS Client under the medusa.admin.invites property.

All methods in this class require authentication.

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.

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

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

The user accepting the invite.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromiseRequired
Resolves when the invite is accepted successfully.

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

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

payloadAdminPostInvitesPayloadRequired
The invite to be created.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromiseRequired
Resolves when the invite is created successfully.

delete

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

Example

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

idstringRequired
The invite's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.

list

Retrieve a list of invites.

Example

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

customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminListInvitesRes>Required
Resolves to the list of invites.

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

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

idstringRequired
The invite's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromiseRequired
Resolves when the invite is resent successfully.
Was this section helpful?