Delphi DLL 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

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
sbResponseBody: HCkStringBuilder;
jsonResponse: HCkJsonObject;
object: PWideChar;
url: PWideChar;
has_more: Boolean;
i: Integer;
count_i: Integer;
id: PWideChar;
account_balance: Integer;
created: Integer;
currency: PWideChar;
default_source: Boolean;
delinquent: Boolean;
description: Boolean;
discount: Boolean;
email: Boolean;
livemode: Boolean;
shipping: Boolean;
sourcesObject: PWideChar;
sourcesHas_more: Boolean;
sourcesTotal_count: Integer;
sourcesUrl: PWideChar;
subscriptionsObject: PWideChar;
subscriptionsHas_more: Boolean;
subscriptionsTotal_count: Integer;
subscriptionsUrl: PWideChar;
j: Integer;
count_j: Integer;

begin
rest := CkRest_Create();

//  URL: https://api.stripe.com/v1/customers?limit=3
bTls := True;
port := 443;
bAutoReconnect := True;
success := CkRest_Connect(rest,'api.stripe.com',port,bTls,bAutoReconnect);
if (success <> True) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_SetAuthBasic(rest,'STRIPE_SECRET_KEY','');

sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/v1/customers?limit=3',sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

jsonResponse := CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

object := CkJsonObject__stringOf(jsonResponse,'object');
url := CkJsonObject__stringOf(jsonResponse,'url');
has_more := CkJsonObject_BoolOf(jsonResponse,'has_more');
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'data');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    id := CkJsonObject__stringOf(jsonResponse,'data[i].id');
    object := CkJsonObject__stringOf(jsonResponse,'data[i].object');
    account_balance := CkJsonObject_IntOf(jsonResponse,'data[i].account_balance');
    created := CkJsonObject_IntOf(jsonResponse,'data[i].created');
    currency := CkJsonObject__stringOf(jsonResponse,'data[i].currency');
    default_source := CkJsonObject_IsNullOf(jsonResponse,'data[i].default_source');
    delinquent := CkJsonObject_BoolOf(jsonResponse,'data[i].delinquent');
    description := CkJsonObject_IsNullOf(jsonResponse,'data[i].description');
    discount := CkJsonObject_IsNullOf(jsonResponse,'data[i].discount');
    email := CkJsonObject_IsNullOf(jsonResponse,'data[i].email');
    livemode := CkJsonObject_BoolOf(jsonResponse,'data[i].livemode');
    shipping := CkJsonObject_IsNullOf(jsonResponse,'data[i].shipping');
    sourcesObject := CkJsonObject__stringOf(jsonResponse,'data[i].sources.object');
    sourcesHas_more := CkJsonObject_BoolOf(jsonResponse,'data[i].sources.has_more');
    sourcesTotal_count := CkJsonObject_IntOf(jsonResponse,'data[i].sources.total_count');
    sourcesUrl := CkJsonObject__stringOf(jsonResponse,'data[i].sources.url');
    subscriptionsObject := CkJsonObject__stringOf(jsonResponse,'data[i].subscriptions.object');
    subscriptionsHas_more := CkJsonObject_BoolOf(jsonResponse,'data[i].subscriptions.has_more');
    subscriptionsTotal_count := CkJsonObject_IntOf(jsonResponse,'data[i].subscriptions.total_count');
    subscriptionsUrl := CkJsonObject__stringOf(jsonResponse,'data[i].subscriptions.url');
    j := 0;
    count_j := CkJsonObject_SizeOfArray(jsonResponse,'data[i].sources.data');
    while j < count_j do
      begin
CkJsonObject_putJ(jsonResponse,j);
        j := j + 1;
      end;

    j := 0;
    count_j := CkJsonObject_SizeOfArray(jsonResponse,'data[i].subscriptions.data');
    while j < count_j do
      begin
CkJsonObject_putJ(jsonResponse,j);
        j := j + 1;
      end;

    i := i + 1;
  end;

CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(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"
      }
    }
  ]
}