klaviyo / php-klaviyo

PHP wrapper for the Klaviyo API
59 stars 48 forks source link

Property value as array #75

Open wardwj opened 2 years ago

wardwj commented 2 years ago

Passing an array (defined as a string) as a property value and encountering this issue:

Output in klaviyo: testing = [\"jon\",\"doe\"]

This is the code I'm using to create this $this->klaviyo->updateProfile($klaviyoProfile["id"], ['testing' => '["jon","doe"]' ])

wardwj commented 2 years ago

As per the documentation this is how the format is documented to save array values on a property:

https://help.klaviyo.com/hc/en-us/articles/115005237648-About-Data-Types#list6

smoucka commented 2 years ago

Hi @wardwj

Thanks for bringing this to our attention.

I think there are two issues at hand here. First it appears the array in your example is actually a string which is why you see the escaped quotes on the profile in Klaviyo. Unfortunately, if you pass that array in as an array rather than a string Klaviyo will save each value in the array with an index suffix e.g. test[0], test[1]. The issue occurs when converting the query parameters to a query string. Php's http_build_query automatically indexes the keys e.g. ?test[0]=jon&test[1]=doe and Klaviyo expects those values to instead be formatted like ?test=jon&test=doe.

While this can be resolved in future versions of the SDK, in the meantime you can hopefully utilize the identify endpoint. One thing to note, you'll need to use the email address instead of the profile ID. Here's an example:

$toUpdate = new KlaviyoProfile(
    array(
        '$email' => 'someone@example.com',
        'a_list_prop' => ['hey', 'hi', 'howdy']
    )
);
$client->publicAPI->identify($toUpdate, true);
1stevengrant commented 2 years ago

any ETA of when this is likely to resolve?