CRUD via the SDK for JS

I’ve been looking at the SDK for JS and trying to find methods for creating and updating entries as well as creating assets. Is there some other SDK that allows full CRUD?

I’d like to avoid having to make direct HTTP calls to the API from within my Angular app.

Thanks

Hi @ian.r.sherwood!

Have you checked out our developer documentation at https://www.contentful.com/developers/docs/references/content-management-api/?

Specifically you can click on this link to see the following code snippet:

const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

// Create entry
client.getSpace('<space_id>')
.then((space) => space.createEntryWithId('<content_type_id>', '<entry_id>', {
  fields: {
    title: {
      'en-US': 'Entry title'
    }
  }
}))
.then((entry) => console.log(entry))
.catch(console.error)

// Update entry
client.getSpace('<space_id>')
.then((space) => space.getEntry('<entry_id>'))
.then((entry) => {
  entry.fields.title['en-US'] = 'New entry title'
  return entry.update()
})
.then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
.catch(console.error)

You also might check out this tutorial about using Contentful in an Angular project.

Hope this helps!

Charlie,

With respect, the tutorial just scratches the surface and illustrates the fact that using Contentful in Angular pretty much requires developers to write their own service to encapsulate two or three of the SDKs.

It would truly helpful if there was an npm package or prebuilt Angular service that exposed the full power of the SDK. If one already exists, I’d love to know about it, but all the examples I’ve found (like the basic one from UseAllFive) just allow entry retrieval. Any non-trivial app requires CRUD support to some level.

I truly enjoy Contentful and have used it in a few projects so far. If I find the time, I’ll make the code I’m writing into something general I’ll put it on GitHub and let you know.

Thanks,

Ian