How to Create a Get Request to Process Through All Paginated Pages with Limited Coding Experience?

Worked! Got this warning.

No idea what that is.

Thank you so much for taking the time to help me! :pray:

Ah! The issue is here: projects = projects.concat(response);

now that the full response is being returned, you probably need to do this: projects = projects.concat(response.data);

or response.body

Whatever it is.

Why would adding in

props: {
    projectId: {
      type: "string",
      label: "Project ID",
    },

cause the

TypeError
Cannot read properties of undefined (reading 'split')

to happen again?

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    projectId: {
      type: "string",
      label: "Project ID",
    },
  },
  async run({ steps, $ }) {
    let lineItems = [];
    let url = `https://app.jetbuilt.com/api/projects/${this.projectId}/purchasing?page=1`;

    while (url) {
      const response = await axios($, {
        url,
        returnFullResponse: true,
        headers: {
          Authorization: `Token token=`,
        },
      });

      lineItems = lineItems.concat(response.data.line_items);
      const linkHeader = response.headers.link;
      const nextLink = linkHeader.split(',').find(link => link.includes('rel="next"'));

      if (nextLink) {
        url = nextLink.split(';')[0].trim().slice(1, -1);
      } else {
        url = null;
      }
    }

    return lineItems;
  },
});

I guess it might be possible if there’s only one page for a certain project? (thus no link for other pages)

Might need to add a new exit condition: if (!!response.headers.link) return lineItems;