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

294
Visualizações
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 Respostas
Responde à pergunta

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 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