klaviyo-api-php icon indicating copy to clipboard operation
klaviyo-api-php copied to clipboard

Undefined array key 3 on getProfiles endpoint when using more than 3 arguments

Open HappydaysAS opened this issue 1 year ago • 3 comments

I have the following line of code

$response = $this->klaviyoAPI->Profiles->getProfiles(filter: $filter, apiKey: config('klaviyo.api_token'), page_cursor: $pageCursor, page_size: $pageSize);

This give me the following error

   ErrorException 

  Undefined array key 3

  at vendor/klaviyo/api/lib/Subclient.php:47
     43▕             $param_position = $param->getPosition();
     44▕ 
     45▕             if (count($args) > $param_position) {
     46▕ 
  ➜  47▕                 $page_cursor = $args[$param_position];
     48▕                 if ($page_cursor != NULL) {
     49▕                     $page_cursor = $this->new_page_cursor($page_cursor);
     50▕ 
     51▕                     $args[$param_position] = $page_cursor;

If I reduce the amount of arguments to 3, it works correctly. Also, by stepping through the code above, I notice that the $args array in line 47 does indeed not have numbered keys, but named keys, which is why it fails.

HappydaysAS avatar Feb 16 '24 08:02 HappydaysAS

thank you for bringing this to our attention! we will take a look.

sanfordj avatar Feb 16 '24 16:02 sanfordj

I believe the issue is that you are using page_cursor with page_size. I don't believe you can use both at the same time (as page_cursor encodes a fixed page_size from the initial query.

I will look into this further to see if I find anything else to share.

jon-batscha avatar Feb 16 '24 19:02 jon-batscha

This is because the Subclient logic here in __call() does not properly support named arguments.

See my PR for a proper fix for this: https://github.com/klaviyo/klaviyo-api-php/pull/50

sc0ttkclark avatar Mar 11 '24 22:03 sc0ttkclark