Last active
August 29, 2015 14:07
-
-
Save jpotts/2864740b9da49babca09 to your computer and use it in GitHub Desktop.
Create content using the contentful CM API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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