Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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