library(httr)
library(jsonlite)
# 🔐 Replace with your private key
klaviyo_api_key <- "pk_XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# 👤 Replace with real customer email to test
email_to_search <- "example@example.com"
# 📦 Build API call
res <- GET(
url = "https://a.klaviyo.com/api/profiles/",
query = list(filter = paste0("equals(email,'", email_to_search, "')")),
add_headers(
`Authorization` = paste("Klaviyo-API-Key", klaviyo_api_key),
`Accept` = "application/json",
`revision` = "2025-04-15"
)
)
# ✅ Check response
print(status_code(res)) # Should return 200
parsed <- content(res, "text", encoding = "UTF-8")
profile_data <- fromJSON(parsed)
# 🔍 Inspect results
print(profile_data$data)