Skip to content

Instantly share code, notes, and snippets.

@jpotts
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts/2864740b9da49babca09 to your computer and use it in GitHub Desktop.
Save jpotts/2864740b9da49babca09 to your computer and use it in GitHub Desktop.
Create content using the contentful CM API
var contentful = require('contentful-management');
var spaceId = 'someSpaceId';
var accessToken = 'someAccessToken';
var contentTypeId = 'someContentTypeId';
var client = contentful.createClient({
space: spaceId,
accessToken: accessToken,
secure: true,
host: 'api.contentful.com'
});
// a custom "Generic Content" content type
var entry = {
fields: {
name: {
'en-US': "Take a Trip!"
},
description: {
'en-US': "Title for page 4"
},
geoCode: {
'en-US': ["all"]
},
loginState: {
'en-US': ["all"]
},
pageId: {
'en-US': ["page4"]
},
placementId: {
'en-US': ["banner"]
},
expDate: {
'en-US': "2014-10-31T00:00:00-05:00"
},
pubDate: {
'en-US': "2014-10-01T00:00:00-05:00"
},
content: {
'en-US': {title: "Take a Trip", imgSrc:""}
}
}
};
client.getSpace(spaceId).catch(function(error) {
console.log('Could not find space: ' + spaceId);
throw error;
}).then(function(space) {
space.createEntry(contentTypeId, entry).catch(function(error) {
console.log('Error creating entry: ' + error.toString());
throw error;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment