Skip to content

Available Methods

REST API

All requests to the REST API use the https://api.cosmicjs.com base URL. Current version is v2.

https://api.cosmicjs.com/v2

Node.js

Install the official NPM module for Cosmic with the following command:

npm i cosmicjs

GraphQL

Base URL

All GraphQL API examples use the following API endpoint:

https://graphql.cosmicjs.com/v3

GraphQL Playground

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.

Full screen

Cosmic CLI

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.

Installation

Install the CLI globally:

npm i -g cosmic-cli

Login

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: starman@gmail.com
? Password: [hidden]
Authenticated

Usage

All Cosmic CLI commands are of the format:

cosmic [command] [options]

Use Bucket

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 slug, read_key, and write_key access keys in Bucket Settings > API Access after logging into your account.

$ cosmic use-bucket your-bucket-slug --read_key your-read-key --write_key your-write-key
Now using bucket your-bucket-slug

Now you are ready to use any of the commands to have full control over your Bucket!

Help

Run cosmic -h for a list of all commands.

Run cosmic [command] -h for details on options for a specific command.

Commands

For a list of the options for a command, use cosmic [command] -h

  • begin Guide to Getting Started
  • login
  • which-user outputs the email of the current user
  • which-bucket 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]
  • get-object-types
  • 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]