PowerBuilder 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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
oleobject loo_JsonResponse
string ls_Object
string ls_Url
integer li_Has_more
integer i
integer li_Count_i
string ls_Id
integer li_Account_balance
integer li_Created
string ls_Currency
integer li_Default_source
integer li_Delinquent
integer li_Description
integer li_Discount
integer li_Email
integer li_Livemode
integer li_Shipping
string ls_SourcesObject
integer li_SourcesHas_more
integer li_SourcesTotal_count
string ls_SourcesUrl
string ls_SubscriptionsObject
integer li_SubscriptionsHas_more
integer li_SubscriptionsTotal_count
string ls_SubscriptionsUrl
integer j
integer li_Count_j

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://api.stripe.com/v1/customers?limit=3
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("api.stripe.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthBasic("STRIPE_SECRET_KEY","")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/v1/customers?limit=3",loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbResponseBody
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.LoadSb(loo_SbResponseBody)

ls_Object = loo_JsonResponse.StringOf("object")
ls_Url = loo_JsonResponse.StringOf("url")
li_Has_more = loo_JsonResponse.BoolOf("has_more")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("data")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Id = loo_JsonResponse.StringOf("data[i].id")
    ls_Object = loo_JsonResponse.StringOf("data[i].object")
    li_Account_balance = loo_JsonResponse.IntOf("data[i].account_balance")
    li_Created = loo_JsonResponse.IntOf("data[i].created")
    ls_Currency = loo_JsonResponse.StringOf("data[i].currency")
    li_Default_source = loo_JsonResponse.IsNullOf("data[i].default_source")
    li_Delinquent = loo_JsonResponse.BoolOf("data[i].delinquent")
    li_Description = loo_JsonResponse.IsNullOf("data[i].description")
    li_Discount = loo_JsonResponse.IsNullOf("data[i].discount")
    li_Email = loo_JsonResponse.IsNullOf("data[i].email")
    li_Livemode = loo_JsonResponse.BoolOf("data[i].livemode")
    li_Shipping = loo_JsonResponse.IsNullOf("data[i].shipping")
    ls_SourcesObject = loo_JsonResponse.StringOf("data[i].sources.object")
    li_SourcesHas_more = loo_JsonResponse.BoolOf("data[i].sources.has_more")
    li_SourcesTotal_count = loo_JsonResponse.IntOf("data[i].sources.total_count")
    ls_SourcesUrl = loo_JsonResponse.StringOf("data[i].sources.url")
    ls_SubscriptionsObject = loo_JsonResponse.StringOf("data[i].subscriptions.object")
    li_SubscriptionsHas_more = loo_JsonResponse.BoolOf("data[i].subscriptions.has_more")
    li_SubscriptionsTotal_count = loo_JsonResponse.IntOf("data[i].subscriptions.total_count")
    ls_SubscriptionsUrl = loo_JsonResponse.StringOf("data[i].subscriptions.url")
    j = 0
    li_Count_j = loo_JsonResponse.SizeOfArray("data[i].sources.data")
    do while j < li_Count_j
        loo_JsonResponse.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JsonResponse.SizeOfArray("data[i].subscriptions.data")
    do while j < li_Count_j
        loo_JsonResponse.J = j
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_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"
      }
    }
  ]
}