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

Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Csv;
import com.chilkatsoft.chilkat2.HttpCurl;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

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

        HttpCurl curl = new HttpCurl();
        StringBuilder cmd = new StringBuilder();
        JsonObject json = new JsonObject();

        int replaced = 0;

        // Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
        String fromTime = "1790812800";
        String untilTime = "1793491200";

        Csv ledger = new Csv();
        ledger.setHasColumnNames(true);
        int outputRow = 0;
        ledger.setColumnName(0, "id");
        ledger.setColumnName(1, "created");
        ledger.setColumnName(2, "source");
        ledger.setColumnName(3, "reporting_category");
        ledger.setColumnName(4, "amount");
        ledger.setColumnName(5, "fee");
        ledger.setColumnName(6, "net");
        ledger.setColumnName(7, "currency");

        StringBuilder pageSuffix = new StringBuilder();
        boolean more = true;
        String cursor = "";
        while (more) {
            // 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.setString("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.getAsString());
            replaced = cmd.replace("@FROM@", fromTime);
            replaced = cmd.replace("@UNTIL@", untilTime);
            replaced = cmd.replace("@KEY@", apiKey);
            try {
                curl.doYourThing(cmd.getAsString());
            } catch (ChilkatException e) {
                System.out.println("No HTTP response. Chilkat failure code: " + curl.getFailReason());
                return;
            }

            try {
                curl.getResponseJson(json);
                success = true;
            } catch (ChilkatException e) {
                success = false;
            }
            if ((curl.getStatusCode() != 200) || (!success)) {
                System.out.println("Stripe HTTP " + curl.getStatusCode() + "  Request-Id: " + curl.getResponseHeaderField("Request-Id"));
                if (success) {
                    System.out.println(json.stringOf("error.message"));
                }

                return;
            }

            int i = 0;
            int count = json.sizeOfArray("data");
            while (i < count) {
                json.setI(i);
                ledger.setCell(outputRow, 0, json.stringOf("data[i].id"));
                ledger.setCell(outputRow, 1, json.stringOf("data[i].created"));
                ledger.setCell(outputRow, 2, json.stringOf("data[i].source"));
                ledger.setCell(outputRow, 3, json.stringOf("data[i].reporting_category"));
                ledger.setCell(outputRow, 4, json.stringOf("data[i].amount"));
                ledger.setCell(outputRow, 5, json.stringOf("data[i].fee"));
                ledger.setCell(outputRow, 6, json.stringOf("data[i].net"));
                ledger.setCell(outputRow, 7, json.stringOf("data[i].currency"));
                outputRow = outputRow + 1;
                i = i + 1;
            }

            more = json.boolOf("has_more");
            if (more) {
                String next = json.stringOf("data[i].id");
                if ((count < 1) || (("".equals(next)) || (next.equals(cursor)))) {
                    System.out.println("Invalid pagination cursor.");
                    return;
                }

                cursor = next;
                pageSuffix.setString("&starting_after=");
                pageSuffix.append(cursor);
            }
        }

        try {
            ledger.saveFile("stripe-balance-transactions.csv");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Exported rows: " + outputRow);
    }
}