To keep things concise, all requests to the REST API use the
$BASE_URL variable to indicate the following base URL:
Install the official NPM module for Cosmic with the following command:
npm i cosmicjs
All GraphQL API examples use the following API endpoint:
Use the playground for a full interactive demonstration. Use the "Docs" and "Schema" buttons on the right side for documentation on models, queries, inputs, and descriptions.
Use the Cosmic CLI to log in to your Cosmic account, manage Buckets, data, files and users within your Buckets, all from the comfort of your command line interface.
Install the CLI globally:
npm i -g cosmic-cli
Use your credentials (from https://app.cosmicjs.com/login) to login on the command line. You will only have to do this once. If you used GitHub to sign up, you can also login via authentication token which you can find at https://app.cosmicjs.com/account/authentication
$ cosmic login? Email: firstname.lastname@example.org? Password: [hidden]Authenticated
All Cosmic CLI commands are of the format:
cosmic [command] [options]
Now that you are logged in, you can connect to any of your Buckets on your account. The
use-bucket command will set your Bucket config options. You can set your read and write access keys with this command for later use to interact with your Bucket content. Find your Bucket
write_key access keys in Your Bucket > Settings > API Access after logging into your account.
$ cosmic use-bucket your-bucket-slug --read_key your-read-key --write_key your-write-keyNow using bucket your-bucket-slug
Now you are ready to use any of the commands to have full control over your Bucket!
cosmic -h for a list of all commands.
cosmic [command] -h for details on options for a specific command.
For a list of the options for a command, use
cosmic [command] -h
Guide to Getting Started
outputs the email of the current user
outputs the slug of the current Bucket
- get-buckets [options]
shows Buckets available to user
- use-bucket [options][slug]
- add-bucket [options]
- delete-bucket [options]
- get-objects [options]
- get-object [options]
- add-object-type [options]
- edit-object-type [options]
- delete-object-type [options]
- add-object [options]
- edit-object [options]
- delete-object [options]
- add-media [options]
- get-media [options]
- delete-media [options]
- add-user [options]