fork download
  1. <?php
  2. function verifyKlaviyoKey($apiKey) {
  3. $url = "https://a...content-available-to-author-only...o.com/api/accounts/";
  4.  
  5. $ch = curl_init($url);
  6.  
  7. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  8. "Authorization: Klaviyo-API-Key $apiKey",
  9. "Accept: application/json"
  10. ]);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  12.  
  13. $response = curl_exec($ch);
  14. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  15.  
  16. curl_close($ch);
  17.  
  18. if ($httpCode === 200) {
  19. return true; // ✅ Key is valid
  20. } else {
  21. return false; // ❌ Invalid or insufficient permissions
  22. }
  23. }
  24.  
  25. // Example usage:
  26. $apiKey = "pk_618e84267f485d10a093d8ddd8f82aa67f";
  27.  
  28. if (verifyKlaviyoKey($apiKey)) {
  29. echo "✅ API Key is valid!";
  30. } else {
  31. echo "❌ API Key is invalid or unauthorized.";
  32. }
  33. ?>
  34.  
Success #stdin #stdout 0.03s 26256KB
stdin
Standard input is empty
stdout
❌ API Key is invalid or unauthorized.