Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.7.0+

Stripe: Export a period of account activity

See more Stripe Examples

Export account activity for a UTC date range to CSV, including transaction references, fees, net amounts, and currencies.

Stripe documentation and cURL example

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local success = false

-- Requires an unlocked Chilkat bundle. See Global Unlock Sample.
-- Supply a restricted sandbox key from merchant-controlled configuration.
local apiKey = "YOUR_STRIPE_TEST_KEY"

local curl = chilkat.HttpCurl.new()
local cmd = chilkat.StringBuilder.new()
local json = chilkat.JsonObject.new()

local replaced = 0

-- Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
local fromTime = "1790812800"
local untilTime = "1793491200"

local ledger = chilkat.Csv.new()
ledger.has_column_names = true
local outputRow = 0
ledger:set_column_name(0, "id")
ledger:set_column_name(1, "created")
ledger:set_column_name(2, "source")
ledger:set_column_name(3, "reporting_category")
ledger:set_column_name(4, "amount")
ledger:set_column_name(5, "fee")
ledger:set_column_name(6, "net")
ledger:set_column_name(7, "currency")

local pageSuffix = chilkat.StringBuilder.new()
local more = true
local cursor = ""
while more do
    -- curl -X GET "https://api.stripe.com/v1/balance_transactions?created%5Bgte%5D={fromTime}&created%5Blt%5D={untilTime}&limit=100" \
    --   -u "$STRIPE_API_KEY:" \
    --   -H "Stripe-Version: 2026-10-28.endive"
    cmd:set_string("curl -X GET \"https://api.stripe.com/v1/balance_transactions?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@\"")
    cmd:append(" -u \"@KEY@:\"")
    cmd:append(" -H \"Stripe-Version: 2026-10-28.endive\"")
    replaced = cmd:replace("@CURSOR@", pageSuffix:get_as_string())
    replaced = cmd:replace("@FROM@", fromTime)
    replaced = cmd:replace("@UNTIL@", untilTime)
    replaced = cmd:replace("@KEY@", apiKey)
    success = curl:do_your_thing(cmd:get_as_string())
    if not success then
        print("No HTTP response. Chilkat failure code: " .. curl.fail_reason)
        return
    end

    success = curl:get_response_json(json)
    if (curl.status_code ~= 200) or (not success) then
        print("Stripe HTTP " .. curl.status_code .. "  Request-Id: " .. curl:get_response_header_field("Request-Id"))
        if success then
            print(json:string_of("error.message"))
        end

        return
    end

    local i = 0
    local count = json:size_of_array("data")
    while i < count do
        json.i = i
        ledger:set_cell(outputRow, 0, json:string_of("data[i].id"))
        ledger:set_cell(outputRow, 1, json:string_of("data[i].created"))
        ledger:set_cell(outputRow, 2, json:string_of("data[i].source"))
        ledger:set_cell(outputRow, 3, json:string_of("data[i].reporting_category"))
        ledger:set_cell(outputRow, 4, json:string_of("data[i].amount"))
        ledger:set_cell(outputRow, 5, json:string_of("data[i].fee"))
        ledger:set_cell(outputRow, 6, json:string_of("data[i].net"))
        ledger:set_cell(outputRow, 7, json:string_of("data[i].currency"))
        outputRow = outputRow + 1
        i = i + 1
    end

    more = json:bool_of("has_more")
    if more then
        local next_ = json:string_of("data[i].id")
        if (count < 1) or ((next_ == "") or (next_ == cursor)) then
            print("Invalid pagination cursor.")
            return
        end

        cursor = next_
        pageSuffix:set_string("&starting_after=")
        pageSuffix:append(cursor)
    end
end

success = ledger:save_file("stripe-balance-transactions.csv")
if not success then
    print(ledger.last_error_text)
    return
end

print("Exported rows: " .. outputRow)