We believe you should have total control of your data. That’s why Braintree’s API gives you the flexibility to generate your own custom reports, allowing you to focus on what’s important to your business without being subject to the limits of our standard reports. You can start setting up your own reporting as soon as you’ve integrated with Braintree.

note

As you scale your business, you may outgrow our standard reports, and having your own reporting in place is crucial. We strongly recommend that you build out custom reporting that fully encompasses your interactions with Braintree, including all transactions and customers you create.

Sample reporting script

This script is a sample of one of many ways that you can generate your own custom reports via the API by:

  • Using the Braintree API to search for all transactions with a particular status
  • Iterating over those results and pulling specific transaction values
  • Adding those details for each transaction to a new row of the output CSV

Remember to

  1. Enter your own API keys
  2. Use the header row fields to define which values you want in the report
Node.js
var fs = require('fs');
var braintree = require("braintree");
var stream = require('stream');
var readable = require('stream').Readable;
var csvWriter = require('csv-write-stream');
var date = require('date-utils');
var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: "enter merchant ID",
  publicKey: "enter public key",
  privateKey: "enter private key"
});

var today = Date.today();

/*using API for finding a transaction
var find = gateway.transaction.find("transactionID", function (err, transaction) {
  //console.dir(transaction);
  console.log('BT1transaction='+transaction.type+' Amount='+transaction.amount+' Status='+transaction.status+' Mechant account id='+transaction.merchantAccountId
    );
});
*/

/* running throu a search response list from a Search stream
var stream = gateway.transaction.search(function (search) {
  search.customerEmail().is("jen@example.com");
}, function (err, response) {
  response.each(function (err, transaction) {
    //console.log(transaction.disbursementDetails.settlementAmount);
  });
});
*/

// create the read and write streams
var streambt = gateway.transaction.search(function (search) {
    console.log('Todays date: '+today);

    //Use this to find transactions between specic dates
    search.settledAt().between(Date.yesterday(),Date.today());

    //Use this to find transactions for a specific email
    //search.customerEmail().is("jen@example.com");
});

// Use this to find the length of the Stream or no of objects
// before you extract it into a csv
streambt.on("ready", function () {
  console.log(streambt.searchResponse.length());
});

// You can either create a Array of JSON objects for the transactions
var transactions=[];

// or just put the JSON object stream in to stream writer
var writer = csvWriter({ headers: ['id', 'status', 'type']});
writer.pipe(fs.createWriteStream('out.csv'));

streambt.on("data", function (transaction) {
  //console.log(transaction);
  //console.dir(transaction);
  writer.write(transaction);
  transactions.push(transaction);
});

streambt.on("end", function () {
  //console.log(streambt.searchResponse.ids.length);
  writer.end();
  //console.log('transactions length ='+ transactions.length);
  for (var i = transactions.length - 1; i >= 0; i--) {
    console.log(transactions[i].disbursementDetails.settlementAmount);
  };
});

Search limit

Transaction searches return a maximum of 50,000 results; all other searches return a maximum of 10,000 results.

See also