JS is codeless API

Hi - I have a basic JS to query data from external API, which I am running under codeless logic block as shown below. I am not getting an error but not getting any data as well. Is this the correct way of doing it?

Hi @LetMeTest,

Could you please provide a code from the js_test?

const https = require("https");


const pageCount = 100;

// set allRecords to receive data, start from beginning of call
let allRecords = [],
  noOfPages = 0,
  cursor = 0;

function getRecords(cursor, token) {
  return new Promise((resolve, reject) => {
    const options = {
      hostname: "https://xxxx.xxxx.com/version1/api/obj/orders",
      path: `/getRecords?cursor=${cursor}`,
      method: "GET",
      headers: {
        Authorization: `Bearer ${token}`,
      },
    };
    const req = https.request(options, (res) => {
      let data = "";
      res.on("data", (chunk) => {
        data += chunk;
      });
      res.on("end", () => {
        const { remaining, results } = JSON.parse(data).response;
        if (allRecords.length) {
          noOfPages -= 1;
        } else {
          noOfPages = Math.ceil(remaining / pageCount);
        }
        cursor += results.length;
        allRecords = [...allRecords, ...results];
        resolve(Boolean(noOfPages));
      });
    });
    req.on("error", (err) => {
      reject(err);
    });
    req.end();
  });
}

(async function () {
  const bearerToken = "xxxx";
  await doWhilst(
    async () => {
      try {
        return await getRecords(cursor, bearerToken);
      } catch (err) {
        console.log("error: ", err);
      }
    },
    (hasMorePages, cb2) => {
      cb2(null, hasMorePages);
    }
  );
})();

Can someone please help here?

Hello,

I apologize, but I am afraid we would not be able to help you with your code. Debugging developer’s code, especially one that does not use any of the Backendless APIs is outside of our support charter. I recommend using debugging to see where the problem is.

Regards,
Mark