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

295
Vistas
Error to Execute a Mutation with GraphQL in Google App Script

I managed to use similar code below for query GraphQL using Google App Script. However, it's not working when I changed to use on mutation (code below).

Error code is 400 with text: {"errors":[{"message":"GraphQL operations must contain a non-empty query or a persistedQuery extension.","extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}

I just started to learn Google App Script & Javascript, not sure how to resolve this issue after search few hours on the net. Some help would be appreciate. Thanks in advance.

function get_auth_headers(){
  email = "test@mail.com"
  password ="test"

  var query = "mutation={ \
                userLogin(input:{email:\"" + email + "\",password:\"" + password + "\"}){ \
                  token \
                } \
              }";

  Logger.log(query)
  var url1 = "https://server.matters.news/graphql?";
  url = encodeURI(url1 + query)
  Logger.log(url)
  var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true });
  Logger.log("code: " + response.getResponseCode());
  Logger.log("text: " + response.getContentText());
  var response = UrlFetchApp.fetch(url,{method: 'GET', headers: {'Content-Type': 'application/json'}});
  var lists = JSON.parse((response.getContentText()));
  Logger.log(lists);
}

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

0

Managed to get answer from https://speckle.guide/dev/js-app-script.html Refers code below for your reference if you have same issue.

function get_auth_headers() {
  //email = "test@gmail.com"
  //password ="test"

  let url = "https://server.matters.news/graphql";
  let graphql = JSON.stringify({
    query: `mutation($input: UserLoginInput!) {userLogin(input: $input) {token}}`,
    variables: {
      input: {
        email: email,
        password: password,
      },
    },
  });

  let params = {
    method: "POST",
    payload: graphql,
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer YOUR_PERSONAL_TOKEN",
    },
  };

  var response = UrlFetchApp.fetch(url, params);
  var lists = JSON.parse((response.getContentText()));
  //Logger.log(lists['data']['userLogin']['token']);
  return lists['data']['userLogin']['token'];
}

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