Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!