Authentication
Get your token
Send your email
and password
to receive your access token. Your access token will be used to add Buckets to your account as well as other account-related access. Sign up to set up your Cosmic account.
If you signed up using a 3rd party (Google or GitHub) you can create a new password in Account Settings > Password.
Note
You do not need to use the token to access your Bucket content. Your Bucket
has its own read and write keys for restricted access. See the API
introduction to learn how to get your Bucket
access keys.
Parameter | Required | Type | Description |
---|---|---|---|
required | String | Your Cosmic login email | |
password | required | String | Your Cosmic login password |
Methods
- Node.js
- cURL
- GraphQL
- CLI
Cosmic.authenticate()
Example Request
const Cosmic = require("cosmicjs")(); // double parentheses to init function without tokenconst data = await Cosmic.authenticate({email: "you@youremail.com",password: "yourpassword",});
Example Response
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXV.eyJlbWFpbCI6InNwaXJvbnl..."}
Use your token
You can use the Authentication token using REST requests to the API
Example -> Get Buckets
Required
token
must be passed as Authorization Bearer
in the header of the request.
Methods
- Node.js
- cURL
- GraphQL
- CLI
Cosmic.getBuckets()
Example Request
const Cosmic = require("cosmicjs")({token: "your-token-from-auth-request", // optional});const data = await Cosmic.getBuckets();