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

258
Vistas
How To Solve "Expected type object but found type string" in REST API calls? (reactjs, javascript)

I'm trying to use following Auth0 API call: https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id

const sUserMetadata = async () => {
                const domain = "xxxxxxxxxxxxxxx"

                try {
                    const accessToken = await getAccessTokenSilently({
                        audience: `${domain}/api/v2/`,
                        scope: "update:current_user_metadata",
                    });


                    const userDetailsByIdUrl = `${domain}/api/v2/users/${user.sub}`;
                    const metadataResponse = await fetch(userDetailsByIdUrl, {
                        method: 'PATCH',
                        headers: {
                            Authorization: `Bearer ${accessToken}`,
                        },
                        body: { "email_verified": true }
                    })

                    let user_metadata = await metadataResponse;
                    console.log(user_metadata)
                } catch (e) {
                    console.log(e.message);
                }
            };

            sUserMetadata().then(r => null);

I am receiving following response error:

{"statusCode":400,"error":"Bad Request","message":"Payload validation error: 'Expected type object but found type string'.","errorCode":"invalid_body"}

Obviously the Body-Tag provides it in the correct form with Bracets {} so it Should! be an Object.

I have tried:

  • JSON.parse()

  • I have tried to add Content-Type which results in a freaking "SYNTAX ERROR" because of the - in content-type which doesnt make any sense because under chrome debugger I can obviously see that there is a property called content-type: text/plain;charset=UTF-8 and I have no idea how else I am supposed to change this?

    headers: {
                 Authorization: `Bearer ${accessToken}`,
                 Content-Type: 'application/json',
             },
    
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Putting Content-Type inside Apostrophes 'Content-Type' so it doesn't give a Syntax Error and then you using JSON.Stringify() at the Body-Tag part fixes the problem.

const metadataResponse = await fetch(userDetailsByIdUrl, {
                        method: 'PATCH',

                        headers: {
                            Authorization: `Bearer ${accessToken}`,
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify({ "user_metadata" : { "addresses": {"work_address": "100 Industrial Way"} }}),
                    })

PS: save me from javascript pls

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