Modify API request's URL parameter from Transformer

Is there any way to modify the URL parameter of an API request via the Transformer, such that I can increment the pagination for my request?

For example, when I query a certain API, I receive the following JSON response:

{
  "data": [
    {
      "id": "1000",
      "type": "employees",
      "attributes": {
        "id": "1000",
        "first_name": "John",
        "last_name": "Smith",
        "email": "john.smith@company.com",
      }
    },
    {
      "id": "1001",
      "type": "employees",
      "attributes": {
        "id": "1001",
        "first_name": "Jane",
        "last_name": "Doe",
        "email": "jane.doe@company.com",
      }
    }
  ],
  "meta": {
    "pagination": {
      "per_page": 25,
      "page": 1,
      "total": 99
    }
  }
}

I want to use the Transformer to recursively call {{ getEmployees.data }} and increment the URL parameter page[number] by 1 while data.meta.total - (data.meta.pagination.page * data.meta.per_page) > 0 and concatenate the results.

The query url is currently: "https://partners.humi.ca/v1/employees?page[number]=1"
Although I am trying to assign a variable {{ page }} to the URL parameter, it doesn't seem to be mutable.

Hi @ThomasLu_EarthDaily Thanks for reaching out!

This community post may be of interest to you! You can follow a similar approach to call your api query and pass in new page values. To clarify, you'll need to use a JS query, since JS transformers cannot trigger actions.

Is there a more elegant way of doing this?

const fetchAll = (p, data, hasMorePages) => {

  // Base case: there are no more pages
  if (!hasMorePages) return data
  
  // Wrap the query result in a promise
  return new Promise(resolve => {
    return getHumiEmployees.trigger({
      additionalScope: { page : p },
      onSuccess: queryResult => {
        // Add the records from this query to all the records we have so far
        const newResults = data.concat(queryResult.data)                  
        return resolve(fetchAll(p + 1, newResults, (queryResult.meta.pagination.total - (queryResult.meta.pagination.per_page * queryResult.meta.pagination.page) > 0)))
      }
    })
  })
}

return fetchAll(1, [], true)

Hi @ThomasLu_EarthDaily I think this looks good! Are you running into any limitations with this code?