Help with API calls with limitations and data transformation from retrieved data

I would like to complete data of a table I retrieve from an API with data from another API to complete the information needed.

The simplified workflow is:

Problems?

Sure. I get two main issues:

  1. The API has a limitation, so I set the splitonbatches node to retrieve the first 20 but I don’t get the next ones. Maybe I can use also proxies.

  2. I achieved calling the second API which has the attributes I need, but it retrieves them in an awkward way that blows my mind. My expected (or desired) result was: ids, usd, usd_market_cap instead of this monster:

Please share the workflow

{
  "nodes": [
    {
      "parameters": {
        "url": "https://api.llama.fi/chains",
        "options": {
          "splitIntoItems": true
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        340,
        400
      ]
    },
    {
      "parameters": {
        "batchSize": 20,
        "options": {
          "reset": false
        }
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        520,
        400
      ]
    },
    {
      "parameters": {
        "url": "https://api.coingecko.com/api/v3/simple/price",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "ids",
              "value": "={{$json[\"gecko_id\"]}}"
            },
            {
              "name": "vs_currencies",
              "value": "usd"
            },
            {
              "name": "include_market_cap",
              "value": "true"
            }
          ]
        }
      },
      "name": "HTTP Request3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        400
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "HTTP Request3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

What should I do? Thanks!

You do not need to use the Split Batches node. n8n automatically will do the looping for you. Remove the split batches node and reference in the second HTTP request the output of the first HTTP request. Be aware that you are gonna have to limit the number of requests or you are going to hit the rate limit of the CounGecko API. To do that, you can use the parameters Batch Interva and Batch Size. They located under options in the HTTP request.

Use the function node below to map the data to something more readable.

const results = []

for (const item of items) {
  const key = Object.keys(item.json)[0]
  results.push({
    json: {
          id: key,
    ...item.json[key]
    }
  })
}

return results
2 Likes

Worked amazing. Thanks!