C Stripe: Retrieve a Customer

Back to Index

Retrieves the details of an existing customer. You need only supply the unique customer identifier that was returned upon customer creation.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq \
   -u STRIPE_SECRET_KEY:

C Example

#include <C_CkRest.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jsonResponse;
    const char *id;
    const char *object;
    int account_balance;
    int created;
    const char *currency;
    BOOL default_source;
    BOOL delinquent;
    BOOL description;
    BOOL discount;
    BOOL email;
    BOOL livemode;
    BOOL shipping;
    const char *sourcesObject;
    BOOL sourcesHas_more;
    int sourcesTotal_count;
    const char *sourcesUrl;
    const char *subscriptionsObject;
    BOOL subscriptionsHas_more;
    int subscriptionsTotal_count;
    const char *subscriptionsUrl;
    int i;
    int count_i;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/v1/customers/cus_CBbgVLJqv487Oq",sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

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

    id = CkJsonObject_stringOf(jsonResponse,"id");
    object = CkJsonObject_stringOf(jsonResponse,"object");
    account_balance = CkJsonObject_IntOf(jsonResponse,"account_balance");
    created = CkJsonObject_IntOf(jsonResponse,"created");
    currency = CkJsonObject_stringOf(jsonResponse,"currency");
    default_source = CkJsonObject_IsNullOf(jsonResponse,"default_source");
    delinquent = CkJsonObject_BoolOf(jsonResponse,"delinquent");
    description = CkJsonObject_IsNullOf(jsonResponse,"description");
    discount = CkJsonObject_IsNullOf(jsonResponse,"discount");
    email = CkJsonObject_IsNullOf(jsonResponse,"email");
    livemode = CkJsonObject_BoolOf(jsonResponse,"livemode");
    shipping = CkJsonObject_IsNullOf(jsonResponse,"shipping");
    sourcesObject = CkJsonObject_stringOf(jsonResponse,"sources.object");
    sourcesHas_more = CkJsonObject_BoolOf(jsonResponse,"sources.has_more");
    sourcesTotal_count = CkJsonObject_IntOf(jsonResponse,"sources.total_count");
    sourcesUrl = CkJsonObject_stringOf(jsonResponse,"sources.url");
    subscriptionsObject = CkJsonObject_stringOf(jsonResponse,"subscriptions.object");
    subscriptionsHas_more = CkJsonObject_BoolOf(jsonResponse,"subscriptions.has_more");
    subscriptionsTotal_count = CkJsonObject_IntOf(jsonResponse,"subscriptions.total_count");
    subscriptionsUrl = CkJsonObject_stringOf(jsonResponse,"subscriptions.url");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"sources.data");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"subscriptions.data");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        i = i + 1;
    }



    CkRest_Dispose(rest);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "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"
  }
}