Swift Requires Chilkat v11.7.0+
Swift
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 Swift Downloads
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 email = CkoStringBuilder()!
email.setString(value: "billing+east@example.com")
// Show every match so the operator can check the internal account reference.
let pageSuffix = CkoStringBuilder()!
var more: Bool = true
var cursor: String? = ""
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"
cmd.setString(value: "curl -X GET \"https://api.stripe.com/v1/customers?email=@EMAIL@&limit=100@CURSOR@\"")
cmd.append(value: " -u \"@KEY@:\"")
cmd.append(value: " -H \"Stripe-Version: 2026-10-28.endive\"")
replaced = cmd.replace(value: "@CURSOR@", replacement: pageSuffix.getAsString()).intValue
replaced = cmd.replace(value: "@EMAIL@", replacement: email.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
}
var i: Int = 0
var count: Int = json.size(ofArray: "data").intValue
while (i < count) {
json.i = i
print("\(json.string(of: "data[i].id")!) | \(json.string(of: "data[i].name")!) | \(json.string(of: "data[i].email")!) | \(json.string(of: "data[i].metadata.account_ref")!)")
i = i + 1
}
more = json.bool(of: "has_more")
if more == true {
var next: String? = json.string(of: "data[i].id")
if (count < 1) || (next == "") || (next == cursor) {
print("Invalid pagination cursor.")
return
}
cursor = next
pageSuffix.setString(value: "&starting_after=")
pageSuffix.append(value: cursor)
}
}
}