Batch Requests
Some Roblox API endpoints accept arrays of IDs but impose limits on how many you can pass at once. fetchApiSplit automatically chunks your request and merges the results.
Basic Usage
Section titled “Basic Usage”import { fetchApiSplit, isAnyErrorResponse } from 'rozod';import { getGamesIcons } from 'rozod/lib/endpoints/thumbnailsv1';
const results = await fetchApiSplit( getGamesIcons, { universeIds: [1, 2, 3, /* ...hundreds more */ ] }, { universeIds: 100 }, // split into chunks of 100 (response) => response.data, // transform each chunk's response);
if (isAnyErrorResponse(results)) { console.error(results.message);} else { // results is T[] — one transformed result per chunk const allIcons = results.flat(); console.log(allIcons);}How It Works
Section titled “How It Works”- You specify which top-level parameter to split and the maximum chunk size
fetchApiSplitdivides the array into chunks- All chunks are fetched in parallel via
Promise.all - Each response is passed through your optional transform function
- Results are returned as an array (one entry per chunk)
Parameters
Section titled “Parameters”fetchApiSplit( endpoint, // The endpoint to fetch params, // Full parameters (with the large array) max, // Object mapping top-level parameter names to max chunk sizes transform?, // Optional function to transform each response requestOptions?,)max— An object where keys are top-level parameter names and values are the maximum array length per request. For example,{ universeIds: 100 }splits theuniverseIdsarray into groups of 100. Only works for parameters at the top level of the params object (not nested insidebody).transform— Optional function that receives each chunk’s response and returns the data you want. If omitted, the raw response is returned.
Example: Multi-Get Thumbnails
Section titled “Example: Multi-Get Thumbnails”import { fetchApiSplit, isAnyErrorResponse } from 'rozod';import { getGamesMultigetThumbnails } from 'rozod/lib/endpoints/thumbnailsv1';
const universeIds = [1, 2, 3, /* ...hundreds of IDs */ ];
const results = await fetchApiSplit( getGamesMultigetThumbnails, { universeIds, countPerUniverse: 1 }, { universeIds: 100 }, (response) => response.data,);
if (!isAnyErrorResponse(results)) { const allThumbnails = results.flat(); console.log(`Fetched thumbnails for ${allThumbnails.length} games`);}Error Handling
Section titled “Error Handling”If any chunk fails, fetchApiSplit returns the first error as an AnyError. The remaining chunks may still complete (they run in parallel), but only the error is returned.