Transactions → Google Sheets overview
Import affiliate transactions, commissions, and statuses into Google Sheets using Apps Script. The sample defaults to the last 30 days, paginates safely, and flattens JSON:API transaction payloads into a Transactions tab.
Endpoint:
GET /api/v1/transactions
List responses wrap JSON:API under transactions. Use start_date and end_date for analytics windows; status accepts values such as pending, approved, paid, or corrected.
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. Transactions 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 transactions into Google Sheets.
* Requires the shared Hi Energy client helpers in this Apps Script project.
*
* Defaults to the last 30 days. Adjust START_DATE / END_DATE / STATUS as needed.
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Hi Energy AI')
.addItem('Import transactions', 'importHiEnergyTransactions')
.addToUi();
}
function importHiEnergyTransactions() {
var START_DATE = isoDateDaysAgo_(30);
var END_DATE = isoDateToday_();
var STATUS = ''; // e.g. 'approved', 'pending', 'paid', 'corrected'
var page = 1;
var perPage = 100;
var allRows = [];
var maxPages = 50;
while (page <= maxPages) {
var payload = hiEnergyApiGet_('/api/v1/transactions', {
start_date: START_DATE,
end_date: END_DATE,
status: STATUS,
page: page,
per_page: perPage,
include_total: false
});
var records = extractJsonApiCollection_(payload, ['transactions', 'data']);
if (!records.length) break;
records.forEach(function(item) {
allRows.push(flattenJsonApiItem_(item));
});
if (records.length < perPage) break;
page += 1;
}
var count = writeObjectsToSheet_('Transactions', allRows, true);
SpreadsheetApp.getActiveSpreadsheet().toast('Imported ' + count + ' transactions', 'Hi Energy AI', 5);
}Useful query parameters
| Parameter | Purpose |
|---|---|
start_date / end_date |
Inclusive transaction date bounds (YYYY-MM-DD). |
status |
pending, approved, paid, corrected (and multi-status where supported). |
advertiser_id / advertiser_slug |
Limit to one program. |
network_id / network_slug |
Filter by affiliate network. |
currency |
ISO currency code such as USD. |
sort_by / sort_order |
Order results for reporting workflows. |
page / per_page |
Offset pagination used by the importer loop. |
FAQ
Use the paste-ready Apps Script on this page to call GET /api/v1/transactions with X-Api-Key, paginate results, and write rows to a Transactions sheet.
Start with the last 30 days sample. Narrow or widen START_DATE and END_DATE for finance closes, publisher reports, or reconciliations.
Transactions search depends on Searchkick/Elasticsearch availability and your publisher scope. Check the Transactions API docs and API status page if requests fail.
Yes. Set STATUS to pending, approved, paid, or corrected, and optionally filter by advertiser_id, network_id / network_slug, currency, and sort_by / sort_order before running the importer.
Yes. Flattened JSON:API attributes typically include commission, sale amount, currency, status, and related advertiser or network fields your account can see.
Yes. This page publishes TechArticle, HowTo, FAQPage, BreadcrumbList, WebSite SearchAction, and related endpoint ItemList structured data for answer engines.