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

210
Vistas
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 Respuestas
Responde la pregunta

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