Tcl Stripe: List all Customers

Back to Index

Returns a list of your customers. The customers are returned sorted by creation date, with the most recent customers appearing first.

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

CURL Command

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

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.stripe.com/v1/customers?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/customers?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 account_balance [CkJsonObject_IntOf $jsonResponse "data[i].account_balance"]
    set created [CkJsonObject_IntOf $jsonResponse "data[i].created"]
    set currency [CkJsonObject_stringOf $jsonResponse "data[i].currency"]
    set default_source [CkJsonObject_IsNullOf $jsonResponse "data[i].default_source"]
    set delinquent [CkJsonObject_BoolOf $jsonResponse "data[i].delinquent"]
    set description [CkJsonObject_IsNullOf $jsonResponse "data[i].description"]
    set discount [CkJsonObject_IsNullOf $jsonResponse "data[i].discount"]
    set email [CkJsonObject_IsNullOf $jsonResponse "data[i].email"]
    set livemode [CkJsonObject_BoolOf $jsonResponse "data[i].livemode"]
    set shipping [CkJsonObject_IsNullOf $jsonResponse "data[i].shipping"]
    set sourcesObject [CkJsonObject_stringOf $jsonResponse "data[i].sources.object"]
    set sourcesHas_more [CkJsonObject_BoolOf $jsonResponse "data[i].sources.has_more"]
    set sourcesTotal_count [CkJsonObject_IntOf $jsonResponse "data[i].sources.total_count"]
    set sourcesUrl [CkJsonObject_stringOf $jsonResponse "data[i].sources.url"]
    set subscriptionsObject [CkJsonObject_stringOf $jsonResponse "data[i].subscriptions.object"]
    set subscriptionsHas_more [CkJsonObject_BoolOf $jsonResponse "data[i].subscriptions.has_more"]
    set subscriptionsTotal_count [CkJsonObject_IntOf $jsonResponse "data[i].subscriptions.total_count"]
    set subscriptionsUrl [CkJsonObject_stringOf $jsonResponse "data[i].subscriptions.url"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jsonResponse "data[i].sources.data"]
    while {[expr $j < $count_j]} {
        CkJsonObject_put_J $jsonResponse $j
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jsonResponse "data[i].subscriptions.data"]
    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/customers",
  "has_more": false,
  "data": [
    {
      "id": "cus_CBbgVLJqv487Oq",
      "object": "customer",
      "account_balance": 0,
      "created": 1516662781,
      "currency": "usd",
      "default_source": null,
      "delinquent": false,
      "description": null,
      "discount": null,
      "email": null,
      "livemode": false,
      "metadata": {},
      "shipping": null,
      "sources": {
        "object": "list",
        "data": [
        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/customers/cus_CBbgVLJqv487Oq/sources"
      },
      "subscriptions": {
        "object": "list",
        "data": [
        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/customers/cus_CBbgVLJqv487Oq/subscriptions"
      }
    }
  ]
}