Skip to content

Instantly share code, notes, and snippets.

@itailulu
Last active January 9, 2024 15:18
Show Gist options
  • Save itailulu/7d8fdb43ef9813da66a47a9ed26e1686 to your computer and use it in GitHub Desktop.
Save itailulu/7d8fdb43ef9813da66a47a9ed26e1686 to your computer and use it in GitHub Desktop.
Get Make.com Scenarios Consumption
/**
* ----------------------------------------------
* Make Scenarios Consumption Data Extractor
* ----------------------------------------------
* This script is designed to efficiently extract and process
* consumption data for various scenarios from Make's API.
* It enables easy integration of this data into spreadsheet applications
* by formatting the data for straightforward copy-pasting.
*
*
* Instructions for Using the Script:
*
* 1. Retrieve Your Team ID:
* - Navigate to your Make account.
* - Look at the URL in your browser; it should look something like "https://eu1.make.com/123123/scenarios?folder=all&tab=all".
* - Extract the numeric part (e.g., "123123") from the URL. This is your Team ID.
*
* 2. Obtain the Headers Object:
* - Open the Chrome Developer Tools (DevTools).
* - Click on the 'Network' tab.
* - Visit or refresh the Make page to capture the network requests.
* - Look for a request that starts with "https://eu1.make.com/api/v2/scenarios".
* - Right-click on one of these requests and select 'Copy' > 'Copy as fetch'.
* - Paste the copied fetch request into a text editor.
* - Extract the 'headers' object from this fetch request.
*
* 3. Prepare and Run the Script:
* - Replace the placeholder in the script with your actual Team ID.
* - Place the extracted 'headers' object into the variable 'myHeaders' in the script.
* - Run the entire script in the DevTools Console.
* - After the script has processed and displayed the data in the console, right-click on the output string and select 'Copy string content'. You can then paste this copied data directly into your preferred spreadsheet application, such as Excel or Google Sheets, for further analysis or storage
*
* The script will fetch the necessary data, process it, and copy the result to your clipboard. You can then paste this data into a spreadsheet.
*/
/** CONFIG - Enter your data here **/
myHeaders = {} // YOUR HEADERS HERE
teamId = 123123 // YOUR TEAM ID HERE
/** CODE **/
async function fetchScenarios() {
const scenariosResponse = await fetch(`https://eu1.make.com/api/v2/scenarios?teamId=${teamId}&pg%5Blimit%5D=10000`, {
method: "GET",
"headers": myHeaders,
"referrer": `https://eu1.make.com/${teamId}/scenarios?folder=all&tab=all`,
"referrerPolicy": "same-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
const scenariosData = await scenariosResponse.json();
const consumptionsResponse = await fetch(`https://eu1.make.com/api/v2/scenarios/consumptions?teamId=${teamId}`, {
method: "GET",
"headers": myHeaders,
"referrer": `https://eu1.make.com/${teamId}/scenarios?folder=all&tab=all`,
"referrerPolicy": "same-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
const consumptionsData = await consumptionsResponse.json();
return combineAndSortData(scenariosData.scenarios, consumptionsData.scenarioConsumptions);
}
function combineAndSortData(scenarios, consumptions) {
const combinedData = scenarios.map(scenario => {
const consumption = consumptions.find(c => c.scenarioId === scenario.id) || {};
return {
name: scenario.name,
id: scenario.id,
operations: consumption.operations || 0,
transfer: consumption.transfer || 0
};
});
// Sort by operations or transfer, here I'm using operations
combinedData.sort((a, b) => b.operations - a.operations);
return combinedData;
}
function formatDataForSpreadsheet(data) {
let formattedString = "Name\tID\tOperations\tTransfer\n"; // Header row
data.forEach(item => {
formattedString += `${item.name}\t${item.id}\t${item.operations}\t${item.transfer}\n`;
});
return formattedString;
}
await fetchScenarios().then(data => {
const formattedData = formatDataForSpreadsheet(data);
console.table(data);
return formattedData;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment