Giter VIP home page Giter VIP logo

contentful-management.js's Introduction

contentful-management.js

Javascript client for Contentful's Content Management API:

Supported browsers/environments:

  • Chrome
  • Firefox
  • IE10
  • node.js >= 0.8

Install

In node, using npm:

npm install contentful-management

Note: The next minor version release of dist/contentful-management.min.js will be much smaller. Please use a package manager to keep your JS dependencies up to date and get the newest version right when it's ready!

Usage

Create an access token for the Content Management API first. Use it as the accessToken parameter when creating the client.

var contentful = require('contentful-management');

var client = contentful.createClient({
  // A valid access token for your user (see above on how to create a valid access token)
  accessToken: 'b4c0n73n7fu1',

  // Enable or disable SSL. Enabled by default.
  secure: true
});

var log = console.log.bind(console); // wat

// Get Space
client.getSpace('foobar').then(log, log);

// Get all Entries
client.getSpace('foobar').then(function(space) {
  return space.getEntries();
}).then(log, log);

For now, please check out the Content Management API documentation to learn how the API and the JavaScript client work.

Examples

This library comes with a few example scripts

Cloning a Space

View Source

This clones a Space's complete content model & content. It's intended to be used to create one-time clones of Spaces, not for synchronization.

$ example/clone-space.js \
  --access-token $CONTENTFUL_ACCESS_TOKEN \
  --source-space-id $SOURCE_SPACE_ID \
  --destination-space-id $DESTINATION_SPACE_ID

Omit the destination-space-id parameter to make the script create a Space. When doing that you might have to specify a destination-organization-id parameter if your user is in multiple organizations.

Cloning a Space's Content Types Only

If you just want the content types for a space to be cloned, add the --only-content-types flag.

$ example/clone-space.js \
  --access-token $CONTENTFUL_ACCESS_TOKEN \
  --source-space-id $SOURCE_SPACE_ID \
  --destination-space-id $DESTINATION_SPACE_ID
  --only-content-types

Migrating Entry fields

Sometimes you need to migrate content from one field to another. This is a script which migrates all values from one field to another field, using a specific mapping function if it's provided. It'll do this for each entry of a specific Content Type in a Space, going through it slice by slice.

Currently this supports mapping from Text to Symbol. But it would be very simple to convert e.g. numbers to symbols or even location strings to locations by geocoding. PRs are very welcome!

View Source

$ example/migrate-fields.js \
    --access-token $CONTENTFUL_MANAGEMENT_API_ACCESS_TOKEN \
    --space-id $SPACE_ID \
    --content-type-id $CONTENT_TYPE_ID \
    --source-field-id $SOURCE_FIELD_ID \
    --destination-field-id $DESTINATION_FIELD_ID

Unit Tests

Set the following environment variables to valid values:

  • CONTENTFUL_ACCESS_TOKEN - a valid access token value
  • CONTENTFUL_MANAGEMENT_HOSTNAME - the Contentful host name (without protocol)

Then execute the unit tests:

npm test

License

MIT

contentful-management.js's People

Contributors

seidtgeist avatar grncdr avatar sdepold avatar joshrowley avatar mcalthrop avatar trodrigues avatar

Watchers

Kyle MacDonald avatar Jeff Escalante avatar James Cloos avatar Carrot avatar Elvin G. Marmol avatar Mike Adamitey avatar  avatar Aleksandra Matiyev avatar Michael Duke avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.