Contentful logo

Contentful Community

Can not update field

#1

I want to update a field when a user clicks the specific image. I added an onClick method to the image, and the function is below.

I got a space.getEntry not a function error at the end.

client.getSpace(‘x18qe0iaxip2’).then((space) => space.getEntry(‘favorited’))
.then((entry) => {
entry.fields.favorited = true
return entry.update()
})
.then(entry => console.log(entry.fields.favorited))

0 Likes

#2

I would confirm you are using the content management API and not the content delivery API. The content delivery API cannot update entries.

If you are using the correct API make sure ‘favorited’ is a valid entry id and that you don’t have to specify a locale ie entry.fields.favorited['en-US'] = true.

Hope that helps!

0 Likes