Sample code for 30+ languages & platforms
Swift 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 Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let curl = CkoHttpCurl()!
    let cmd = CkoStringBuilder()!
    let json = CkoJsonObject()!

    var replaced: Int

    let lookupKey = CkoStringBuilder()!
    lookupKey.setString(value: "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"
    cmd.setString(value: "curl -X GET \"https://api.stripe.com/v1/prices?active=true&lookup_keys%5B%5D=@LOOKUP@&limit=2\"")
    cmd.append(value: " -u \"@KEY@:\"")
    cmd.append(value: " -H \"Stripe-Version: 2026-10-28.endive\"")
    replaced = cmd.replace(value: "@LOOKUP@", replacement: lookupKey.getEncoded(encoding: "url_rfc3986", charset: "utf-8")).intValue
    replaced = cmd.replace(value: "@KEY@", replacement: apiKey).intValue
    success = curl.doYourThing(targetCurl: cmd.getAsString())
    if success != true {
        print("No HTTP response. Chilkat failure code: \(curl.failReason.intValue)")
        return
    }

    success = curl.getResponseJson(json: json)
    if (curl.statusCode.intValue != 200) || (success != true) {
        print("Stripe HTTP \(curl.statusCode.intValue)  Request-Id: \(curl.getResponseHeaderField(name: "Request-Id")!)")
        if success == true {
            print("\(json.string(of: "error.message")!)")
        }

        return
    }

    if (json.size(ofArray: "data").intValue != 1) || (json.bool(of: "has_more") == true) {
        print("Expected one active price for this lookup key.")
        return
    }

    print("id = \(json.string(of: "data[0].id")!)")
    print("lookup_key = \(json.string(of: "data[0].lookup_key")!)")
    print("currency = \(json.string(of: "data[0].currency")!)")
    print("unit_amount_decimal = \(json.string(of: "data[0].unit_amount_decimal")!)")
    print("type = \(json.string(of: "data[0].type")!)")

}