Deals → Google Sheets overview
Use Google Apps Script UrlFetchApp and your Hi Energy AI API key to import active affiliate deals into Google Sheets. This guide includes paste-ready code for pagination, JSON:API flattening, and writing rows to a Deals tab.
Endpoint:
GET /api/v1/deals
List responses nest records under deals.data (JSON:API). The sample flattens id, type, and attributes into spreadsheet columns.
Setup in Google Sheets
- Open a Google Sheet → Extensions → Apps Script.
-
Get your personal API key from
API key docs.
Prefer the
X-Api-Keyheader (these samples already do). -
In Apps Script, open Project Settings → Script properties
and add
HIENERGY_API_KEYwith your key value. - Paste the shared client library, then the resource import script below.
- Click Save, reload the Sheet, and run the import from the Hi Energy AI menu (or Run in the editor).
-
On first run, authorize the script when Google prompts for
UrlFetchApp/ external request permission.
2. Deals import script
Paste this below the shared client, save the project, then run the import function (or use the Hi Energy AI custom menu after reloading the sheet).
/**
* Import affiliate deals into the active Google Sheet.
* Requires the shared Hi Energy client helpers in this Apps Script project.
*
* Run: Extensions → Apps Script → select importHiEnergyDeals → Run
* Optional custom menu: onOpen()
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Hi Energy AI')
.addItem('Import deals', 'importHiEnergyDeals')
.addToUi();
}
function importHiEnergyDeals() {
var page = 1;
var perPage = 100;
var allRows = [];
var maxPages = 20;
while (page <= maxPages) {
var payload = hiEnergyApiGet_('/api/v1/deals', {
page: page,
per_page: perPage,
active: true,
include_total: false
});
var records = extractJsonApiCollection_(payload, ['deals', 'data']);
if (!records.length) break;
records.forEach(function(item) {
allRows.push(flattenJsonApiItem_(item));
});
if (records.length < perPage) break;
page += 1;
}
var count = writeObjectsToSheet_('Deals', allRows, true);
SpreadsheetApp.getActiveSpreadsheet().toast('Imported ' + count + ' deals', 'Hi Energy AI', 5);
}Useful query parameters
| Parameter | Purpose |
|---|---|
active |
Set true to keep only currently active deals. |
exclusive |
Filter exclusive offers when supported for your account. |
advertiser_id |
Limit deals to one advertiser / program. |
country |
Country or country_code filter for geo-targeted deals. |
deal_type |
Filter by deal kind / type labels from the deals API. |
page / per_page |
Offset pagination. The sample walks pages until a short page is returned. |
q / search |
Free-text search across deal content when needed. |
FAQ
Paste the shared Apps Script client and deals importer from this page, store HIENERGY_API_KEY in Script properties, then run importHiEnergyDeals. The script calls GET /api/v1/deals with X-Api-Key and writes flattened rows to a Deals tab.
For Hi Energy AI authentication use your personal API key via X-Api-Key. Google will still ask you to authorize the Apps Script project to call external services with UrlFetchApp.
Nested objects and arrays from JSON:API attributes are stringified so every value fits in a single spreadsheet cell. Expand them with Apps Script or Sheets formulas if you need columnar nested data.
Yes. Edit the sample query parameters such as active, exclusive, advertiser_id, country, deal_type, and search before running importHiEnergyDeals. Pagination walks pages until a short page is returned.
Yes. The Google Sheets importer uses the live GET /api/v1/deals endpoint documented on the Deals API page, scoped to your account permissions and rate limits.
Yes. This page publishes TechArticle, HowTo, FAQPage, BreadcrumbList, WebSite SearchAction, and related endpoint ItemList structured data so answer engines can cite a concrete Apps Script import path.