Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
How to update a single field in a Contentful entry?

Need help updating a field in a CF entry. It is a dropdown field without a default value.

I tried to do that by getting the entry from the CF environment, setting the corresponding field and updating it like this:

        client.getSpace(spaceId)
        .then((space) => {space.getEnvironment(environment)
            .then((environment) => {environment.getEntry('1234567890')
                .then((entry) => {
                    entry.fields = {
                        state: {
                            'en-US': 'Arizona'
                        }
                    }
                    return entry.update()
                })
            })
        })

By doing so, the state value gets updated, but the other existing field values are deleted.

The Contentful documentation for content update states the same here: https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/updating-content, but I cannot find a way to implement their suggestion.

How do I update the state value without losing all the other fields?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When you do

entry.fields = {
  state: {
    'en-US': 'Arizona'
  }
}

You replace the whole fields object by the new one containing only one key: state.
Instead of setting entry.fields, you should set entry.fields.state

Example:

client.getSpace(spaceId)
    .then(space => space.getEnvironment(environment))
    .then(environment => environment.getEntry('1234567890'))
    .then(entry => {
        entry.fields.state = {
            'en-US': 'Arizona'
        }
        return entry.update()
    });

Also: I changed the way you use .then(). One of the benefits of Promises is that you don't have to nest callbacks. Here you are nesting callbacks. You can chain .then() calls to make your code more readable, as I did in the sample above. See: Aren't promises just callbacks?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda