PureBasic 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

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.stripe.com/v1/customers?limit=3
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/v1/customers?limit=3",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)

    object.s
    url.s
    has_more.i
    i.i
    count_i.i
    id.s
    account_balance.i
    created.i
    currency.s
    default_source.i
    delinquent.i
    description.i
    discount.i
    email.i
    livemode.i
    shipping.i
    sourcesObject.s
    sourcesHas_more.i
    sourcesTotal_count.i
    sourcesUrl.s
    subscriptionsObject.s
    subscriptionsHas_more.i
    subscriptionsTotal_count.i
    subscriptionsUrl.s
    j.i
    count_j.i

    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    url = CkJsonObject::ckStringOf(jsonResponse,"url")
    has_more = CkJsonObject::ckBoolOf(jsonResponse,"has_more")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"data")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        id = CkJsonObject::ckStringOf(jsonResponse,"data[i].id")
        object = CkJsonObject::ckStringOf(jsonResponse,"data[i].object")
        account_balance = CkJsonObject::ckIntOf(jsonResponse,"data[i].account_balance")
        created = CkJsonObject::ckIntOf(jsonResponse,"data[i].created")
        currency = CkJsonObject::ckStringOf(jsonResponse,"data[i].currency")
        default_source = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].default_source")
        delinquent = CkJsonObject::ckBoolOf(jsonResponse,"data[i].delinquent")
        description = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].description")
        discount = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].discount")
        email = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].email")
        livemode = CkJsonObject::ckBoolOf(jsonResponse,"data[i].livemode")
        shipping = CkJsonObject::ckIsNullOf(jsonResponse,"data[i].shipping")
        sourcesObject = CkJsonObject::ckStringOf(jsonResponse,"data[i].sources.object")
        sourcesHas_more = CkJsonObject::ckBoolOf(jsonResponse,"data[i].sources.has_more")
        sourcesTotal_count = CkJsonObject::ckIntOf(jsonResponse,"data[i].sources.total_count")
        sourcesUrl = CkJsonObject::ckStringOf(jsonResponse,"data[i].sources.url")
        subscriptionsObject = CkJsonObject::ckStringOf(jsonResponse,"data[i].subscriptions.object")
        subscriptionsHas_more = CkJsonObject::ckBoolOf(jsonResponse,"data[i].subscriptions.has_more")
        subscriptionsTotal_count = CkJsonObject::ckIntOf(jsonResponse,"data[i].subscriptions.total_count")
        subscriptionsUrl = CkJsonObject::ckStringOf(jsonResponse,"data[i].subscriptions.url")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"data[i].sources.data")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"data[i].subscriptions.data")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

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