@tomsd/contentful-handler

1.0.0 • Public • Published

@tomsd/contentful-handler

Installation

npm install @tomsd/contentful-handler

Usage

// with bundler...
import contentful_handler from "@tomsd/contentful-handler";


// getting token
contentful_handler.getOAuthToken({
  client_id:"xxxxxxxxxx",
  redirect_uri:"https://xxxx.xxx.xxx/",
  scope:"content_management_manage"
});

// if got token
const ch = contentful_handler.activate(token);

// getting spaces
ch.getSpaces().then(function(spaces){
  console.log(spaces);
});

// getting environments
ch.getEnvironments(space_id).then(function(environments){
  console.log(environments);
});

// getting content types
ch.getContentTypes(space_id, environment_id).then(function(contenttypes){
  console.log(contenttypes);
});

// getting entries
ch.getEntries(space_id, environment_id).then(function(entries){
  console.log(entries);
});

ch.discoverEnvironments().then(function(envs){
  console.log(envs);
});

// data IO with each content type
const db = ch.getDb(space_id, environment_id, contenttype_id);
db.getItems().then(function(items){
  console.log(items);
});

db.upsertItem({
  // for example content type has "name" and "age" fields.
  name:"alice",
  age:21
}).then(function(upserted_item){
  console.log(upserted_item);
});

db.removeItem(entry_id).then(function(){
  console.log("removed");
});

Readme

Keywords

none

Package Sidebar

Install

npm i @tomsd/contentful-handler

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

28 kB

Total Files

6

Last publish

Collaborators

  • tomsd