Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cApiKey
LOCAL oCurl
LOCAL oCmd
LOCAL oJson
LOCAL nReplaced
LOCAL cFromTime
LOCAL cUntilTime
LOCAL oLedger
LOCAL nOutputRow
LOCAL oPageSuffix
LOCAL nMore
LOCAL cCursor
LOCAL i
LOCAL nCount
LOCAL cNext

nSuccess := 0

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

oCurl := CreateObject("Chilkat.HttpCurl")
oCmd := CreateObject("Chilkat.StringBuilder")
oJson := CreateObject("Chilkat.JsonObject")

//  Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
cFromTime := "1790812800"
cUntilTime := "1793491200"

oLedger := CreateObject("Chilkat.Csv")
oLedger:HasColumnNames := 1
nOutputRow := 0
oLedger:SetColumnName(0, "id")
oLedger:SetColumnName(1, "created")
oLedger:SetColumnName(2, "source")
oLedger:SetColumnName(3, "reporting_category")
oLedger:SetColumnName(4, "amount")
oLedger:SetColumnName(5, "fee")
oLedger:SetColumnName(6, "net")
oLedger:SetColumnName(7, "currency")

oPageSuffix := CreateObject("Chilkat.StringBuilder")
nMore := 1
cCursor := ""
DO WHILE (nMore == 1)
    //  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"
    oCmd:SetString('curl -X GET "https://api.stripe.com/v1/balance_transactions?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@"')
    oCmd:Append(' -u "@KEY@:"')
    oCmd:Append(' -H "Stripe-Version: 2026-10-28.endive"')
    nReplaced := oCmd:Replace("@CURSOR@", oPageSuffix:GetAsString())
    nReplaced := oCmd:Replace("@FROM@", cFromTime)
    nReplaced := oCmd:Replace("@UNTIL@", cUntilTime)
    nReplaced := oCmd:Replace("@KEY@", cApiKey)
    nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
    IF (nSuccess != 1)
        ? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
        oCurl:destroy()
        oCmd:destroy()
        oJson:destroy()
        oLedger:destroy()
        oPageSuffix:destroy()
        RETURN
    ENDIF

    nSuccess := oCurl:GetResponseJson(oJson)
    IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
        ? "Stripe HTTP " + Str(oCurl:StatusCode) + "  Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
        IF (nSuccess == 1)
            ? oJson:StringOf("error.message")
        ENDIF

        oCurl:destroy()
        oCmd:destroy()
        oJson:destroy()
        oLedger:destroy()
        oPageSuffix:destroy()
        RETURN
    ENDIF

    i := 0
    nCount := oJson:SizeOfArray("data")
    DO WHILE (i < nCount)
        oJson:I := i
        oLedger:SetCell(nOutputRow, 0, oJson:StringOf("data[i].id"))
        oLedger:SetCell(nOutputRow, 1, oJson:StringOf("data[i].created"))
        oLedger:SetCell(nOutputRow, 2, oJson:StringOf("data[i].source"))
        oLedger:SetCell(nOutputRow, 3, oJson:StringOf("data[i].reporting_category"))
        oLedger:SetCell(nOutputRow, 4, oJson:StringOf("data[i].amount"))
        oLedger:SetCell(nOutputRow, 5, oJson:StringOf("data[i].fee"))
        oLedger:SetCell(nOutputRow, 6, oJson:StringOf("data[i].net"))
        oLedger:SetCell(nOutputRow, 7, oJson:StringOf("data[i].currency"))
        nOutputRow := nOutputRow + 1
        i := i + 1
    ENDDO
    nMore := oJson:BoolOf("has_more")
    IF (nMore == 1)
        cNext := oJson:StringOf("data[i].id")
        IF ((nCount < 1) .OR. (cNext == "") .OR. (cNext == cCursor))
            ? "Invalid pagination cursor."
            oCurl:destroy()
            oCmd:destroy()
            oJson:destroy()
            oLedger:destroy()
            oPageSuffix:destroy()
            RETURN
        ENDIF

        cCursor := cNext
        oPageSuffix:SetString("&starting_after=")
        oPageSuffix:Append(cCursor)
    ENDIF

ENDDO

nSuccess := oLedger:SaveFile("stripe-balance-transactions.csv")
IF (nSuccess == 0)
    ? oLedger:LastErrorText
    oCurl:destroy()
    oCmd:destroy()
    oJson:destroy()
    oLedger:destroy()
    oPageSuffix:destroy()
    RETURN
ENDIF

? "Exported rows: " + Str(nOutputRow)

oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oLedger:destroy()
oPageSuffix:destroy()