Java 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

Java Example

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.stripe.com/v1/customers?limit=3
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/v1/customers?limit=3",sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

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

    object = jsonResponse.stringOf("object");
    url = jsonResponse.stringOf("url");
    has_more = jsonResponse.BoolOf("has_more");
    i = 0;
    count_i = jsonResponse.SizeOfArray("data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        id = jsonResponse.stringOf("data[i].id");
        object = jsonResponse.stringOf("data[i].object");
        account_balance = jsonResponse.IntOf("data[i].account_balance");
        created = jsonResponse.IntOf("data[i].created");
        currency = jsonResponse.stringOf("data[i].currency");
        default_source = jsonResponse.IsNullOf("data[i].default_source");
        delinquent = jsonResponse.BoolOf("data[i].delinquent");
        description = jsonResponse.IsNullOf("data[i].description");
        discount = jsonResponse.IsNullOf("data[i].discount");
        email = jsonResponse.IsNullOf("data[i].email");
        livemode = jsonResponse.BoolOf("data[i].livemode");
        shipping = jsonResponse.IsNullOf("data[i].shipping");
        sourcesObject = jsonResponse.stringOf("data[i].sources.object");
        sourcesHas_more = jsonResponse.BoolOf("data[i].sources.has_more");
        sourcesTotal_count = jsonResponse.IntOf("data[i].sources.total_count");
        sourcesUrl = jsonResponse.stringOf("data[i].sources.url");
        subscriptionsObject = jsonResponse.stringOf("data[i].subscriptions.object");
        subscriptionsHas_more = jsonResponse.BoolOf("data[i].subscriptions.has_more");
        subscriptionsTotal_count = jsonResponse.IntOf("data[i].subscriptions.total_count");
        subscriptionsUrl = jsonResponse.stringOf("data[i].subscriptions.url");
        j = 0;
        count_j = jsonResponse.SizeOfArray("data[i].sources.data");
        while (j < count_j) {
            jsonResponse.put_J(j);
            j = j+1;
            }

        j = 0;
        count_j = jsonResponse.SizeOfArray("data[i].subscriptions.data");
        while (j < count_j) {
            jsonResponse.put_J(j);
            j = j+1;
            }

        i = i+1;
        }
  }
}

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