Scriptlab custom function getting TypeError: Network request failed when making GET api calls

247 views Asked by At
/**
 * Get Volume .
 * @customfunction
 * @param {string} companyId
 * @param {string} date
 */
async function getVolume(companyId, date) {
  //You can change this URL to any web request you want to work with.
  var myHeaders = new Headers();
  myHeaders.append(
    "Authorization",
    "Bearer token_value"
  );
  var requestOptions = {
    method: "GET",
    headers: myHeaders
  };

  const url = `url value`;
  const response = await fetch(url, requestOptions);
  console.log(response);
  //Expect that status code is in 200-299 range
  if (!response.ok) {
    throw new Error(response.statusText);
  }
  const jsonResponse = await response.json();
  return jsonResponse;
}

when i make the request using postman it works but errors out in excel scriptlab. Please can anyone guide me to the fix to resolve this error.

0

There are 0 answers