Solved

"&" sign in product name or category not submitting using Track API

  • 9 May 2022
  • 1 reply
  • 34 views

Badge

Hi,

I am integrating Track Api to post ‘Placed Order’ event data using PHP curl. It is working fine but if any data string contains ‘&’ or ‘&’ then it is not submitting data.

Example: "ProductName": "Winnie & Pooh", "Categories": [ "Fiction & Drama", "Children" ]

Code Sample

$data = 'data={ "token": "my_token", "event": "Placed Order", "customer_properties": { "$email": "john.smith@test.com", "$first_name": "John", "$last_name": "Smith" }, "properties": { "$event_id": "1234_WINNIEPOOH", "$value": 9.99, "OrderId": "1234", "ProductID": "1111", "SKU": "WINNIEPOOH", "ProductName": "Winnie & Pooh", "Quantity": 1, "ProductURL": "http://www.example.com/path/to/product", "ImageURL": "http://www.example.com/path/to/product/image.png", "Categories": [ "Fiction & Drama", "Children" ], "ProductBrand": "Kids Books" }, "time": 1387302423 }';
  

   $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://a.klaviyo.com/api/track");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS,  ($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: text/html'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $data = curl_exec($ch);   
    $data = json_decode($data, true);
    curl_close($ch);
 

 

icon

Best answer by Dov 9 May 2022, 17:02

View original

1 reply

Userlevel 7
Badge +56

Hi @sachinuser,

Thanks for sharing this with the community.

I noticed you’re already working towards a solution with a member of our support team on this issue. I recommend you continue working with them to investigate the details of your API call for the time being.

Reply