Sample code for 30+ languages & platforms
C Requires Chilkat v11.7.0+

Stripe: Find customer records by billing email

See more Stripe Examples

Find all customers with a given billing email, including addresses with a plus sign. Display the internal account reference so the operator can select the right record.

Stripe documentation and cURL example

Chilkat C Downloads

C
#include <C_CkHttpCurl.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    const char *apiKey;
    HCkHttpCurl curl;
    HCkStringBuilder cmd;
    HCkJsonObject json;
    int replaced;
    HCkStringBuilder email;
    HCkStringBuilder pageSuffix;
    BOOL more;
    const char *cursor;
    int i;
    int count;
    const char *next;

    success = FALSE;

    //  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
    //  Supply a restricted sandbox key from merchant-controlled configuration.
    apiKey = "YOUR_STRIPE_TEST_KEY";

    curl = CkHttpCurl_Create();
    cmd = CkStringBuilder_Create();
    json = CkJsonObject_Create();

    email = CkStringBuilder_Create();
    CkStringBuilder_SetString(email,"billing+east@example.com");

    //  Show every match so the operator can check the internal account reference.

    pageSuffix = CkStringBuilder_Create();
    more = TRUE;
    cursor = "";
    while ((more == TRUE)) {
        //  curl -X GET "https://api.stripe.com/v1/customers?email={email}&limit=100" \
        //    -u "$STRIPE_API_KEY:" \
        //    -H "Stripe-Version: 2026-10-28.endive"
        CkStringBuilder_SetString(cmd,"curl -X GET \"https://api.stripe.com/v1/customers?email=@EMAIL@&limit=100@CURSOR@\"");
        CkStringBuilder_Append(cmd," -u \"@KEY@:\"");
        CkStringBuilder_Append(cmd," -H \"Stripe-Version: 2026-10-28.endive\"");
        replaced = CkStringBuilder_Replace(cmd,"@CURSOR@",CkStringBuilder_getAsString(pageSuffix));
        replaced = CkStringBuilder_Replace(cmd,"@EMAIL@",CkStringBuilder_getEncoded(email,"url_rfc3986","utf-8"));
        replaced = CkStringBuilder_Replace(cmd,"@KEY@",apiKey);
        success = CkHttpCurl_DoYourThing(curl,CkStringBuilder_getAsString(cmd));
        if (success != TRUE) {
            printf("No HTTP response. Chilkat failure code: %d\n",CkHttpCurl_getFailReason(curl));
            CkHttpCurl_Dispose(curl);
            CkStringBuilder_Dispose(cmd);
            CkJsonObject_Dispose(json);
            CkStringBuilder_Dispose(email);
            CkStringBuilder_Dispose(pageSuffix);
            return;
        }

        success = CkHttpCurl_GetResponseJson(curl,json);
        if ((CkHttpCurl_getStatusCode(curl) != 200) || (success != TRUE)) {
            printf("Stripe HTTP %d  Request-Id: %s\n",CkHttpCurl_getStatusCode(curl),CkHttpCurl_getResponseHeaderField(curl,"Request-Id"));
            if (success == TRUE) {
                printf("%s\n",CkJsonObject_stringOf(json,"error.message"));
            }

            CkHttpCurl_Dispose(curl);
            CkStringBuilder_Dispose(cmd);
            CkJsonObject_Dispose(json);
            CkStringBuilder_Dispose(email);
            CkStringBuilder_Dispose(pageSuffix);
            return;
        }

        i = 0;
        count = CkJsonObject_SizeOfArray(json,"data");
        while ((i < count)) {
            CkJsonObject_putI(json,i);
            printf("%s | %s | %s | %s\n",CkJsonObject_stringOf(json,"data[i].id"),CkJsonObject_stringOf(json,"data[i].name"),CkJsonObject_stringOf(json,"data[i].email")
                ,CkJsonObject_stringOf(json,"data[i].metadata.account_ref"));
            i = i + 1;
        }

        more = CkJsonObject_BoolOf(json,"has_more");
        if (more == TRUE) {
            next = CkJsonObject_stringOf(json,"data[i].id");
            if ((count < 1) || (next == "") || (next == cursor)) {
                printf("Invalid pagination cursor.\n");
                CkHttpCurl_Dispose(curl);
                CkStringBuilder_Dispose(cmd);
                CkJsonObject_Dispose(json);
                CkStringBuilder_Dispose(email);
                CkStringBuilder_Dispose(pageSuffix);
                return;
            }

            cursor = next;
            CkStringBuilder_SetString(pageSuffix,"&starting_after=");
            CkStringBuilder_Append(pageSuffix,cursor);
        }

    }



    CkHttpCurl_Dispose(curl);
    CkStringBuilder_Dispose(cmd);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(email);
    CkStringBuilder_Dispose(pageSuffix);

    }