Tcl Stripe: List Balance History

Back to Index

Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.

Documentation: https://stripe.com/docs/api/curl#balance_history

CURL Command

curl https://api.stripe.com/v1/balance/history?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.stripe.com/v1/balance/history?limit=3
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "api.stripe.com" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_SetAuthBasic $rest "STRIPE_SECRET_KEY" ""

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/v1/balance/history?limit=3" $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody

set object [CkJsonObject_stringOf $jsonResponse "object"]
set url [CkJsonObject_stringOf $jsonResponse "url"]
set has_more [CkJsonObject_BoolOf $jsonResponse "has_more"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "data"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set id [CkJsonObject_stringOf $jsonResponse "data[i].id"]
    set object [CkJsonObject_stringOf $jsonResponse "data[i].object"]
    set amount [CkJsonObject_IntOf $jsonResponse "data[i].amount"]
    set available_on [CkJsonObject_IntOf $jsonResponse "data[i].available_on"]
    set created [CkJsonObject_IntOf $jsonResponse "data[i].created"]
    set currency [CkJsonObject_stringOf $jsonResponse "data[i].currency"]
    set description [CkJsonObject_IsNullOf $jsonResponse "data[i].description"]
    set exchange_rate [CkJsonObject_IsNullOf $jsonResponse "data[i].exchange_rate"]
    set fee [CkJsonObject_IntOf $jsonResponse "data[i].fee"]
    set net [CkJsonObject_IntOf $jsonResponse "data[i].net"]
    set source [CkJsonObject_stringOf $jsonResponse "data[i].source"]
    set status [CkJsonObject_stringOf $jsonResponse "data[i].status"]
    set type [CkJsonObject_stringOf $jsonResponse "data[i].type"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jsonResponse "data[i].fee_details"]
    while {[expr $j < $count_j]} {
        CkJsonObject_put_J $jsonResponse $j
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/balance/history",
  "has_more": false,
  "data": [
    {
      "id": "txn_1BnETJGswQrCoh0XxO2tGYr7",
      "object": "balance_transaction",
      "amount": 100,
      "available_on": 1516662781,
      "created": 1516662781,
      "currency": "usd",
      "description": null,
      "exchange_rate": null,
      "fee": 0,
      "fee_details": [
      ],
      "net": 100,
      "source": "ch_1BnETJGswQrCoh0XTs0EERBj",
      "status": "pending",
      "type": "charge"
    }
  ]
}