Contentful logo

Contentful Community

Is it possible to update the field values inside the content

Hi All, very good morning. I am a newbee to contentful though I have good hands on other CMS systems. I tried to use the following code to update the value of a field called “text” in my content. (which is ofcourse an instance of a contenttype) But I am getting below errors.


TypeError: Cannot read property ‘fields’ of undefined
at client.getSpace.then.then.then (/home/ec2-user/expressApp/app.js:32:9)
at
at process._tickCallback (internal/process/next_tick.js:189:7)


HERE is THE CODE: I am using in my app.js



client.getSpace(‘5yalg1fyk63m’)
.then((space) => space.getEntry(‘uMvdBVIYXQ8qgqUWEouu0’))
.then((entry) => console.log(entry))
.then((entry) => {
entry.fields.text[‘en-US’] = ‘We are in Hi-Tech city’
return entry.update()
})
.then((entry) => console.log(Entry ${entry.sys.id} updated.))
.catch(console.error)


I am attaching the complete output for your reference please. It first displays the entry fields and values fine, but cant proceed further when trying to update the value of the field “text”
from text: { ‘en-US’: ‘indian food with north & south flavours kick by chef Sandeep Mehta’ },
to something else using the command => entry.fields.text[‘en-US’] = ‘We are in Hi-Tech city’

Kindly help me as I am unable to proceed further with updating content programmatically.