Skip to content

Users

The following endpoints enable you to get Cosmic user info as well as create, read, update, and delete users in your Bucket.

🔑

Get your token
Your authentication token will be required to perform the following requests.
You can get your token using the authentication method with your email and password.

Endpoints

Get Cosmic user information.

GET /v2/user

Perform actions on users in a Bucket.

GET /v2/buckets/${YOUR_BUCKET_SLUG}/users
POST /v2/buckets/${YOUR_BUCKET_SLUG}/users
GET /v2/buckets/${YOUR_BUCKET_SLUG}/users/:id
PATCH /v2/buckets/${YOUR_BUCKET_SLUG}/users/:id
DELETE /v2/buckets/${YOUR_BUCKET_SLUG}/users/:id

Data Model

AttributeTypeNotes
idStringUnique identifier for User
first_nameStringUser first name
last_nameStringUser last name
emailStringUser email
avatar_urlStringUser avatar URL
usernameStringURL-friendly username
bioStringUser bio
websiteStringUser website
twitterStringUser Twitter profile URL
linkedinStringUser LinkedIn profile URL
githubStringUser GitHub profile URL
companyStringUser company name
locationStringUser location

Get Cosmic User

Gets user info from access token. See authentication section to get access token using email and password.

Required
token must be passed as Authorization Bearer in the header of the request.

Definition

GET /v2/user

Methods

curl https://api.cosmicjs.com/v2/user \
-H "Authorization: Bearer <TOKEN>"

Example Response

{
"user": {
"id": "5f46a1c25711926847cd6b5c",
"first_name": "Quasar",
"last_name": "Jones",
"email": "quasar@milkyway.com",
"username": "quasar",
"avatar_url": "https://imgix.cosmicjs.com/e07818a0-51f0-11eb-9dee-df51ce912356-starry.jpg"
}
}

Get Bucket Users

Gets all users in a Bucket.

Required
token must be passed as Authorization Bearer in the header of the request and you must have admin access to perform this operation.

Definition

GET /v2/buckets/${YOUR_BUCKET_SLUG}/users

Methods

bucket.getUsers()

Example Request

const Cosmic = require("cosmicjs")({
token: "your-token-from-auth-request", // required
});
const bucket = Cosmic.bucket({
slug: "YOUR_BUCKET_SLUG",
});
const data = await bucket.getUsers();

Example Response

{
"users": [
{
"id": "5e4d7eb92850c717ea93dba4",
"first_name": "Starman",
"last_name": "Jones",
"email": "starman@milkyway.com",
"username": "starman",
"bio": "",
"website": "",
"twitter": "",
"linkedin": "",
"github": "",
"company": "",
"location": "",
"avatar_url": "https://imgix.cosmicjs.com/e07818a0-51f0-11eb-9dee-df51ce912356-starry.jpg"
},
{
"id": "5f46a1c25711926847cd6b5c",
"first_name": "Quasar",
"last_name": "Jones",
"email": "quasar@milkyway.com",
"username": "quasar",
"avatar_url": "https://imgix.cosmicjs.com/e07818a0-51f0-11eb-9dee-df51ce912356-quasar.jpg"
}
],
"total": 2
}

Get Bucket User

Gets user by id in your bucket.

Required
token must be passed as Authorization Bearer in the header of the request and you must have admin access to perform this operation.

Definition

GET /v2/buckets/${YOUR_BUCKET_SLUG}/users/:id

Methods

bucket.getUser()

Example Request

const Cosmic = require("cosmicjs")({
token: "your-token-from-auth-request", // required
});
const bucket = Cosmic.bucket({
slug: "YOUR_BUCKET_SLUG",
});
const params = {
id: "5357ef811693be2118000001",
};
const data = await bucket.getUser(params);

Example Response

{
"user": {
"id": "5f46a1c25711926847cd6b5c",
"first_name": "Quasar",
"last_name": "Jones",
"email": "quasar@milkyway.com",
"username": "quasar",
"avatar_url": "https://imgix.cosmicjs.com/e07818a0-51f0-11eb-9dee-df51ce912356-starry.jpg"
}
}

Add User to Bucket

Add a user to your Bucket.

Required
token must be passed as Authorization Bearer in the header of the request and you must have admin access to perform this operation.

Definition

POST /v2/buckets/${YOUR_BUCKET_SLUG}/users
ParameterRequiredTypeDescription
first_namerequiredStringThe new user's first name
last_namerequiredStringThe new user's last name
emailrequiredStringThe new user's email
rolerequiredEnumadmin, developer, editor or contributor
publishing_restrictionsEnumdraft_only
additional_permissionsString / Array[String]users, settings, sort_metafields
object_typesrequired if role is contributorString / Array[String]Your Cosmic login password

Methods

bucket.addUser()

Example Request

const Cosmic = require("cosmicjs")({
token: "your-token-from-auth-request", // required
});
const bucket = Cosmic.bucket({
slug: "YOUR_BUCKET_SLUG",
});
const params = {
email: "newuser@example.com",
role: "editor",
first_name: "Quasar",
last_name: "Jones",
};
const data = await bucket.addUser(params);

Example Response

{
"message": "User added successfully."
}

Edit User in Bucket

Edit user in your Bucket.

Required
token must be passed as Authorization Bearer in the header of the request and you must have admin access to perform this operation.

Definition

PATCH /v2/buckets/${YOUR_BUCKET_SLUG}/users/:id
ParameterRequiredTypeDescription
rolerequiredEnumadmin, developer, editor or contributor
publishing_restrictionsEnumdraft_only
additional_permissionsString / Array[String]users, settings, sort_metafields
object_typesrequired if role is contributorString / Array[String]Object Type slugs

cURL

curl https://api.cosmicjs.com/v2/buckets/${YOUR_BUCKET_SLUG}/users/:id \
-d '{"role":"editor"}' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <TOKEN>" \
-X PATCH

Example Response

{
"message": "User role edited successfully from bucket."
}

Remove Bucket User

Remove user from your Bucket.

Required
token must be passed as Authorization Bearer in the header of the request and you must have admin access to perform this operation.

Definition

DELETE /v2/buckets/${YOUR_BUCKET_SLUG}/users/:id

cURL

curl https://api.cosmicjs.com/v2/buckets/${YOUR_BUCKET_SLUG}/users/:id \
-H "Authorization: Bearer <TOKEN>" \
-X DELETE

Example Response

{
"message": "User removed from bucket successfully."
}