Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Unable to parse json message body in Azure functions

I have following .js code at the start of my Azure Function

module.exports = async function (context, messageObj) {

    context.log('Incoming Message:  ', messageObj)
    const {
        user_name
    } = messageObj

    context.log('typeof messageObj:  ', typeof messageObj)
    context.log('user_name:  ', user_name)

However, the user_name stays undefined.

typeof messageObj:   object    
user_name:   undefined

function.json:

    {
  "bindings": [
    {
      "name": "messageObj",
      "type": "httpTrigger",
      "direction": "in",
    }
  ]
}

My question is why user_name is undefined and not getting parsed, what am i missing?

Ouput of context.log('Incoming Message: ', messageObj):

Incoming Message:   {
  method: 'GET',
  url: 'http://localhost:7071/api/HttpExample',
  originalUrl: 'http://localhost:7071/api/HttpExample',
  headers: {
    accept: '*/*',
    connection: 'keep-alive',
    host: 'localhost:7071',
    'user-agent': 'PostmanRuntime/7.28.4',
    'accept-encoding': 'gzip, deflate, br',
    'content-type': 'text/plain',
    'content-length': '5994',
    'postman-token': '1f1e66c3-19b5-400a-94fb-a91283a53346'
  },
  query: {},
  params: {},
  body: {
    ...
    user_name: 'some user',
    used_subscription: false,
    ...
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

messageObj itself doesn't have any key user_name. You're trying to desctructure it, but it's not there, so it'll return undefined (the same as if you had just tried to directly access it, a la messageObj.user_name).

It seems, based on the information you've provided, that it's actually under body:

const { user_name } = messageObj.body;

In a watered-down example:

const messageObj = {
  foo: 'bar',
  bar: 'foo',
  user: {
    user_name: 'the_user_name',
    foobar: 'barfoo'
  }
}

const { user_name } = messageObj.user;

console.log(user_name);
    

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda