Updated 24 Apr 2025
Unlock the power of ScopeGreen's environmental data directly within your spreadsheets! This guide shows you how to integrate the ScopeGreen API with Google Sheets using a simple copy-paste setup for Google Apps Script.
Once configured, you can use a custom function, =SCOPEGREEN(...), just like any built-in Sheets function (e.g., SUM, VLOOKUP), to fetch Life Cycle Assessment (LCA) metrics directly into your cells.
Before you begin, ensure you have the following:
Follow these steps precisely to add the custom function to your desired Google Sheet:
Open Your Google Sheet: Navigate to the spreadsheet where you want to use the ScopeGreen API.
Access the Script Editor:
(Note: This is a generic image showing where Apps Script is typically found.)Get the Integration Script:
scopegreen.js script file in a new tab:
ScopeGreen Apps Script on GitHubPaste into Your Editor:
function myFunction() {}).scopegreen.js code you copied.CRITICAL: Insert Your API Key:
const API_KEY = "your-api-key";
"your-api-key" with your actual ScopeGreen API key. Ensure your key remains enclosed in the double quotation marks (").
// Correct Example:
const API_KEY = "sgk_live_abcdef1234567890example";
Save Your Script Project:
Authorize the Script (One-Time Action):
=SCOPEGREEN() function within any cell in your sheet, Google needs your permission for the script to run.Congratulations! The =SCOPEGREEN() function is now installed, authorized, and ready to use in your Google Sheet.
You can now call the function from any cell formula.
Function Syntax:
=SCOPEGREEN(itemName, [year], [geography], [metric], [domain], [numMatches], [mode], [notEnglish], [unit])
itemName (String, Required): The primary identifier for the item you want data for (e.g., "steel sheet", "organic cotton"). Must be enclosed in quotes./api/metrics/search endpoint.
year, geography, metric, domain, unit) in quotes. Numeric parameters (numMatches) and boolean parameters (notEnglish) do not need quotes.Usage Examples:
=SCOPEGREEN("concrete block")
=SCOPEGREEN(A1)
=SCOPEGREEN("glass bottle", "", "EU", "Carbon footprint")
lb).
=SCOPEGREEN("polyester fabric", "", "", "Carbon footprint", "", 3, "lite", false, "lb")
When the =SCOPEGREEN() function executes successfully, it outputs data horizontally across the row, filling adjacent columns to the right.
If you requested numMatches=1 (the default), the output typically spans 9 columns:
| Column | Content | Example |
|---|---|---|
| 1 | Match 1: Name | Match 1: Cotton T-shirt |
| 2 | Match 1: Metric Value | 8.3 |
| 3 | Match 1: Metric Unit | kg CO2 eq / kg |
| 4 | Match 1: Year | 2020 |
| 5 | Match 1: Geography | FR |
| 6 | Match 1: Source Name | Agribalyse v3.1 |
| 7 | Match 1: Source Link | https://agribalyse.ademe.fr/data |
| 8 | Match 1: Conversion Info | Unit conversion not requested. |
| 9 | API Explanation | The top match represents... |
numMatches=2, columns for "Match 2" (Name, Value, Unit, Year, Geography, Source Name, Source Link, Conversion Info) will appear after the first match's data, before the final Explanation column. Similarly for numMatches=3."No good match was found..." or "Rate limit exceeded...") will be displayed directly in the cell where you entered the formula.#ERROR! or prompts for authorization repeatedly, try re-saving the script and re-authorizing it by running the function again.SCOPEGREEN calls recalculating simultaneously) can lead to temporary 429 Rate limit exceeded errors. Plan your sheet design accordingly.Logger.log messages printed by the script, which can help pinpoint the issue.