Cosmic JS Blog Stay tuned for community news, company announcements and updates from the Cosmic JS team.

API Updates: Authentication, Add Buckets and More

by Tony Spiro on June 1, 2017

Cosmic JS is on a mission to help you build apps faster.  With this goal in mind, we're happy to announce some additions to our API that will help you manage your application content faster and easier, right from the Cosmic JS API.

We’ve added new endpoints to the API which include:
1. User Authentication
2. Add Buckets to your account
3. Add / Edit / Delete Object Types in your Bucket
4. Add Media to a folder in your Bucket
Check out the Docs page for all of the new additions to the API.

Have you ever wanted to access your account from the API and create new Buckets from the comfort of your own application?  Well now you can thanks to the new POST /authenticate endpoint.  Simply add your Cosmic JS email and password, get your token, then begin performing account-specific tasks from the API.  Currently this only includes Bucket creation, but we plan to open up more features for account management soon.

POST /authenticate

  "email": "",
  "password": "CatsAreAwesome"

Read more about Authentication

Add Buckets
Use the new POST /buckets endpoint to add your new Bucket to your account.  The only required fields are title and a Header with Authorization: Bearer <token>.
Read more about adding Buckets

Add / Edit / Delete Object Types
Add Object Types with POST /:your-bucket-slug/add-object-type
Edit Object Types with PUT /:your-bucket-slug/edit-object-type
Delete Object Types with DELETE /:your-bucket-slug/:object-type-slug
Read more about Object Types

Add Media to Folders
You can now add Media to your Bucket and specify which folder to place it in.

POST /:your-bucket-slug/media

  "media": FILE_DATA,
  "folder": "your-folder-slug"

Read more about adding Media

I hope you find these new additions to the API useful for building your applications.  Browse the API docs to see more detail on how to use the new additions to the API.  If you have any questions reach out to us on Twitter and join our Slack community.

Icon provided by Iconfinder.

You may also like

We're excited to release Cosmic Functions (public beta) to help teams build amazing modern products together with new serverless solutions.

In this article, I’m going to show you how to create an easy-to-manage website navigation menu using the powerful Cosmic JS Metafields.  Because navigation needs to be both flexible and nestable Cosmic JS Metafields allows you to create nestable data structures with parent / child relationships easily with a simple drag and drop in the CMS.  Cosmic JS has made this once time-consuming task easy to implement in any website codebase and intuitive to manage in the Cosmic JS CMS API.

Object Pagination is now live in your Cosmic JS Bucket.

It's now faster and easier to make the content on your webpages dynamic.  The Official Cosmic JS JavaScript Client now comes with a minified browser version that allows you to add the power of Cosmic JS cloud-hosted content into your HTML page with a single file.  Download the Cosmic JS browser file then copy and paste this real-working browser example into an html file to check it out:

<!DOCTYPE html>
  <title>Cosmic JS Easy Browser Example</title>
<h1 id="title">If you see this, something isn't working...</h1>
<div id="content"></div>
<div id="metafields"></div>
<script src="cosmicjs.browser.min.js"></script>
var config = {
  bucket: {
    slug: 'easy-browser-example'
  object: {
    slug: 'home'
Cosmic.getObject(config, config.object, function(err, res) {
  var object = res.object;
  document.getElementById('title').innerHTML = object.title;
  document.getElementById('content').innerHTML = object.content;
  var metafields = object.metafields;
  var images = '';
    images += '<h2>' + metafield.title + '</h2>';
    images += '<img width="300" src="' + metafield.value + '"/>';
    images += '<br><br>';
  document.getElementById('metafields').innerHTML = images;

Sign in to your Cosmic JS account and connect this example to one of your buckets to see how easy it is to create powerful CMS-powered websites and app with Cosmic JS.

In this article I’m going to show you how to get the best of both worlds:  A website that is both dynamic, has content powered by the Cosmic JS API that is also a static website.  Our static website will be easily managed by a content editor using the Cosmic JS CMS and the developer will also be able to use Markdown files.

Today we are announcing a new role, Contributor, which gives you the power to collaborate on content in an entirely new way.