Unicode C 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

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *object;
    const wchar_t *url;
    BOOL has_more;
    int i;
    int count_i;
    const wchar_t *id;
    int account_balance;
    int created;
    const wchar_t *currency;
    BOOL default_source;
    BOOL delinquent;
    BOOL description;
    BOOL discount;
    BOOL email;
    BOOL livemode;
    BOOL shipping;
    const wchar_t *sourcesObject;
    BOOL sourcesHas_more;
    int sourcesTotal_count;
    const wchar_t *sourcesUrl;
    const wchar_t *subscriptionsObject;
    BOOL subscriptionsHas_more;
    int subscriptionsTotal_count;
    const wchar_t *subscriptionsUrl;
    int j;
    int count_j;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/customers?limit=3
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/v1/customers?limit=3",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    object = CkJsonObjectW_stringOf(jsonResponse,L"object");
    url = CkJsonObjectW_stringOf(jsonResponse,L"url");
    has_more = CkJsonObjectW_BoolOf(jsonResponse,L"has_more");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"data");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        id = CkJsonObjectW_stringOf(jsonResponse,L"data[i].id");
        object = CkJsonObjectW_stringOf(jsonResponse,L"data[i].object");
        account_balance = CkJsonObjectW_IntOf(jsonResponse,L"data[i].account_balance");
        created = CkJsonObjectW_IntOf(jsonResponse,L"data[i].created");
        currency = CkJsonObjectW_stringOf(jsonResponse,L"data[i].currency");
        default_source = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].default_source");
        delinquent = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].delinquent");
        description = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].description");
        discount = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].discount");
        email = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].email");
        livemode = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].livemode");
        shipping = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].shipping");
        sourcesObject = CkJsonObjectW_stringOf(jsonResponse,L"data[i].sources.object");
        sourcesHas_more = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].sources.has_more");
        sourcesTotal_count = CkJsonObjectW_IntOf(jsonResponse,L"data[i].sources.total_count");
        sourcesUrl = CkJsonObjectW_stringOf(jsonResponse,L"data[i].sources.url");
        subscriptionsObject = CkJsonObjectW_stringOf(jsonResponse,L"data[i].subscriptions.object");
        subscriptionsHas_more = CkJsonObjectW_BoolOf(jsonResponse,L"data[i].subscriptions.has_more");
        subscriptionsTotal_count = CkJsonObjectW_IntOf(jsonResponse,L"data[i].subscriptions.total_count");
        subscriptionsUrl = CkJsonObjectW_stringOf(jsonResponse,L"data[i].subscriptions.url");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"data[i].sources.data");
        while (j < count_j) {
            CkJsonObjectW_putJ(jsonResponse,j);
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"data[i].subscriptions.data");
        while (j < count_j) {
            CkJsonObjectW_putJ(jsonResponse,j);
            j = j + 1;
        }

        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_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"
      }
    }
  ]
}