Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "new KlaviyoAPI()" example fails because of a missing 'wait_seconds' parameter #68

Closed
primehalo opened this issue Dec 17, 2024 · 3 comments

Comments

@primehalo
Copy link

I have v12.0.1 installed with composer. I'm trying to test this sample code:

$klaviyo = new KlaviyoAPI(
    'YOUR_API_KEY',
    $num_retries = 3,
    $guzzle_options = [],
    $user_agent_suffix = "/YOUR_APP_NAME");
$response = $klaviyo->Metrics->getMetrics();

When I do, I get a deprecation warning about the 'wait_seconds' parameter from klaviyo\api\lib\KlaviyoAPI.php on line 66 followed by a fatal error "Argument 1 passed to GuzzleHttp\Client::__construct() must be of the type array, string given".

It seems the KlaviyoAPI constructor still requires the 'wait_seconds' parameter to be set. It works if I add it as the third parameter:

$klaviyo = new KlaviyoAPI(
    'YOUR_API_KEY',
    $num_retries = 3,
    null,
    $guzzle_options = [],
    $user_agent_suffix = "/YOUR_APP_NAME");
$response = $klaviyo->Metrics->getMetrics();
@ben-horgan-klaviyo
Copy link
Contributor

Thanks for bringing this up, good catch! Looks like our examples use incorrect syntax for named arguments. Here's what it should be:

$klaviyo = new KlaviyoAPI(
    'YOUR_API_KEY',
    num_retries: 3,
    guzzle_options: [],
    user_agent_suffix: "/YOUR_APP_NAME");
$response = $klaviyo->Metrics->getMetrics();

We'll update the README soon.

@primehalo
Copy link
Author

Just to note: Named arguments were introduced with PHP 8 so for PHP 7 that wouldn't work.

@ben-horgan-klaviyo
Copy link
Contributor

README has been updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants