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

194
Vistas
Parse.Cloud.httpRequest returns 'undefined' instead of a response using POST method

I'm making a Parse.Cloud.httpRequest using the POST method to retrieve a token from an API in a Back4App Cloud Code Function called 'retrieveToken'.

Parse.Cloud.define("retrieveToken", async(request) => {
  Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://.......',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "...",
              "password": "...",
              "domain": {
                "name": "..."
              }
            }
          }
        },
        "scope": {
          "project": {
            "id": "..."
          }
        }
      }
    }
  }).then(function(httpResponse) {
    console.log('Token retrieved successfully, Status Code: ', httpResponse.status, ',\n', httpResponse.text);
  }, function(httpResponse) {
    console.error('Failed to retrieve token, retrieveToken: ', httpResponse.status, ',\n', httpResponse.text);
  });
});

It works fine if I delete "project": {"id": "..."} from the 'scope' of the body JSON of the httpRequest.

However, it returns me 'undefined' if I don't delete that chunk of code.

I have to keep that chunk of code there because the API will return me a project-level token only if I specify the project id. Otherwise, I will get a global-level token, which cannot be used for my case.

The API works perfectly with/without the project id specified in Postman.

I have already stuck here for a whole day and still can't figure it out. Where am I doing wrong and how can I get the correct response from Parse.Cloud.httpRequest with the project id specified?

Update:

I found the content-length for the responses are quite different with/without the project id specified using Postman.

'content-length' = 6752 Bytes without the project id specified

'content-length' = 16896 Bytes with the project id specified

By any chance the 'undefined' was caused by the response size limit? If this is the reason, how can I get the correct response? Can I receive the header only?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Part of the problem happens because you are not returning the http response. Try this:

Parse.Cloud.define("retrieveToken", (request) => {
  return Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://.......',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "...",
              "password": "...",
              "domain": {
                "name": "..."
              }
            }
          }
        },
        "scope": {
          "project": {
            "id": "..."
          }
        }
      }
    }
  }).then(function(httpResponse) {
    console.log('Token retrieved successfully, Status Code: ', httpResponse.status, ',\n', httpResponse.text);
    return httpResponse;
  }, function(httpResponse) {
    console.error('Failed to retrieve token, retrieveToken: ', httpResponse.status, ',\n', httpResponse.text);
    return httpResponse;
  });
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

This issue was resolved by adding an environment variable to my Back4App server.

NODE_OPTIONS="--max-http-header-size=16384"

I knew the exact problem (header overflow) by using the code below:

Parse.Cloud.define("retrieveToken", async(request) => {
  return Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://.......',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "...",
              "password": "...",
              "domain": {
                "name": "..."
              }
            }
          }
        },
        "scope": {
          "project": {
            "id": "..."
          }
        }
      }
    }
  });
});

Only the code above returned me the error below, and all other code returned me 'undefined':

[Error]: Parse Error: Header overflow (Code: 141, Version: 1.19.2)

FYI: I'm calling this API

https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens
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