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

209
Visualizações
Multiple returns from api call (json)

i have a problem since i want to get multiple data from a single api call How can i return more than one value from it? I'm running this function, it create the correct logs, but not the return part.

function getParts(axieID) {
  const response = UrlFetchApp.fetch(`https://api.axie.technology/getaxies/${axieID}`);
  const data = JSON.parse(response.getContentText());

  try {
    Logger.log(data.class)
    Logger.log(data.parts[1].name)
    return {
      total: data.class
    }, {
      total1: data.parts[1].name
    };
  } catch (e) {
    Logger.log(e)
    return {
      total: 'error',
      total1: 'error'
    }
  }
}

EDIT

var {total} = getParts(axieID);
  if (total != 'error') {
  sh3.getRange('J'+counter).setValue(total);
  }
  Utilities.sleep(700)
  }
  var {total1} = getParts(axieID);
  if (total1 != 'error') {
  sh3.getRange('K'+counter).setValue(total1);
  }
  Utilities.sleep(700)

SOLUTION (total changed with classe, and total1 changed with orecchie):

function getParts(axieID) {
const response = UrlFetchApp.fetch(`https://api.axie.technology/getaxies/${axieID}`);
const data = JSON.parse(response.getContentText());

try {
  Logger.log(data.class)
  Logger.log(data.parts[1].name)
  return {classe : data.class, orecchie : data.parts[1].name};
}
catch (e) { 
           Logger.log(e)
           return {
               classe: 'error', orecchie: 'error'
           }
   }
}

  var {classe,orecchie} = getParts(axieID);
  if (classe != 'error') {
  sh3.getRange('J'+counter).setValue(classe);
  }
  if (orecchie != 'error') {
  sh3.getRange('K'+counter).setValue(orecchie);
  }
  Utilities.sleep(700)
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Approach # 1:

Return an object which includes both properties like that and easily use them by calling getParts(id).total or getParts(id).total1 :

function getParts(axieID) {
const response = UrlFetchApp.fetch(`https://api.axie.technology/getaxies/${axieID}`);
const data = JSON.parse(response.getContentText());

try {
  Logger.log(data.class)
  Logger.log(data.parts[1].name)
  return {total : data.class, total1 : data.parts[1].name};
}
catch (e) { 
           Logger.log(e)
           return {
               total: 'error', total1: 'error'
           }
   }
}

Approach # 2: By returning array

function getParts(axieID) {
const response = UrlFetchApp.fetch(`https://api.axie.technology/getaxies/${axieID}`);
const data = JSON.parse(response.getContentText());

try {
  Logger.log(data.class)
  Logger.log(data.parts[1].name);
  let total=data.class;
  let total1=data.parts[1].name;
  return [total, total1];
}
catch (e) { 
           Logger.log(e)
           return {
               total: 'error', total1: 'error'
           }
   }
}
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