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

Stripe: Find a catalog price by its lookup key

See more Stripe Examples

Retrieve an active price by its catalog lookup key and read its price ID, currency, amount, and billing type.

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 lookupKey;

    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();

    lookupKey = CkStringBuilder_Create();
    CkStringBuilder_SetString(lookupKey,"support_monthly_usd");

    //  curl -X GET "https://api.stripe.com/v1/prices?active=true&lookup_keys%5B%5D={lookupKey}&limit=2" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    CkStringBuilder_SetString(cmd,"curl -X GET \"https://api.stripe.com/v1/prices?active=true&lookup_keys%5B%5D=@LOOKUP@&limit=2\"");
    CkStringBuilder_Append(cmd," -u \"@KEY@:\"");
    CkStringBuilder_Append(cmd," -H \"Stripe-Version: 2026-10-28.endive\"");
    replaced = CkStringBuilder_Replace(cmd,"@LOOKUP@",CkStringBuilder_getEncoded(lookupKey,"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(lookupKey);
        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(lookupKey);
        return;
    }

    if ((CkJsonObject_SizeOfArray(json,"data") != 1) || (CkJsonObject_BoolOf(json,"has_more") == TRUE)) {
        printf("Expected one active price for this lookup key.\n");
        CkHttpCurl_Dispose(curl);
        CkStringBuilder_Dispose(cmd);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(lookupKey);
        return;
    }

    printf("id = %s\n",CkJsonObject_stringOf(json,"data[0].id"));
    printf("lookup_key = %s\n",CkJsonObject_stringOf(json,"data[0].lookup_key"));
    printf("currency = %s\n",CkJsonObject_stringOf(json,"data[0].currency"));
    printf("unit_amount_decimal = %s\n",CkJsonObject_stringOf(json,"data[0].unit_amount_decimal"));
    printf("type = %s\n",CkJsonObject_stringOf(json,"data[0].type"));


    CkHttpCurl_Dispose(curl);
    CkStringBuilder_Dispose(cmd);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(lookupKey);

    }