Question

API documentation needs correction.

  • 23 November 2021
  • 4 replies
  • 76 views

Badge
  • New Member
  • 9 replies

https://apidocs.klaviyo.com/reference/javascript-client-library

All of the JSON on that page is invalid.

One example of many.

  _learnq.push(['identify', {
'$email' : 'thomas.jefferson@example.com',
'$first_name' : 'Thomas',
'$last_name' : 'Jefferson'
}]);

// should be

_learnq.push(["identify", {
"$email" : "thomas.jefferson@example.com",
"$first_name" : "Thomas",
"$last_name" : "Jefferson"
}]);

The array key is unlikely to matter but after the fits I have been having a little pedantry is in order.

Please fix that page and maybe task someone with the scut work job of cleaning up these types of issues which are all over your documentation.

Thank you,

Alex of the CableWholesale IT etin.

 


4 replies

Userlevel 6
Badge +43

Hi @mac,

Thanks for sharing this feedback with us. And apologies for the frustration you’ve had so far.

To clarify, while many of our APIs are REST-based and utilize JSON for data transfer, these APIs you reference are specifically for our JavaScript client-library, code that runs in a browser. So the data here is being referenced using native JavaScript syntax and not JSON.

We know there is a lot to do to improve our APIs to help avoid some of the frustration you've had. We appreciate your willingness to work with us, and we know things today are not perfect, but we are working hard to make it better.

If you are interested in providing some examples of the work you are trying to accomplish and how we can make it better, and/or any issues you've run into with our APIs, feel free to provide your feedback here. The dev team at Klaviyo are very interested in hearing feedback as they invest more into the developer experience.

 

Badge

Hi Dov,

I have already fixed the issue I was having, I did so by bringing the object in the second array position into compliance with JSON by changing the single quotes to double quotes. In my particular instance I was using Bolt checkout’s callbacks to trigger a track Started Checkout for Klaviyo.

Because my identify call was failing, due to the single quote issue, track Started Checkout was not firing/communicating back to Klaviyo. Here is some code for others facing issues. I assure you the issue was poor documentation which is what I am trying to report since the “Did this help you” modal failed to fire. The original message was also a PSA for anyone hitting similar issues on a custom environment.

/*
The following is an excerpt of JavaScript written by Perl.
It resides in a heredoc in which we fill in the missing pieces.
In order to begin testing and debug I moved the array parameter
into it's own variable. This code is functioning perfectly on my
server.
*/
onShippingDetailsComplete: function (address) {

//console.log('onShippingDetailsComplete');

var test = ['identify',{"\$email":address.email,"\$first_name":address.first_name,"\$last_name":address.last_name}];

/* This is how the documentation instructs a reader. This version fails, so I use the above.
var test = ['identify',{'\$email':address.email,'\$first_name':address.first_name,'\$last_name':address.last_name}];
*/
//console.log(test);

_learnq.push(test);

// This is a Perl variable which contains the complete track Start Checkout
$klaviyo_code

// This function is called when the user proceeds to the shipping options page.
// This is applicable only to multi-step checkout.
// When available the first parameter will contain a user's name and address info.

},

 

 

 

Userlevel 6
Badge +43

Hi @mac,

Thank you for posting this update. I’m glad you were able to resolve this issue and I appreciate you opening up your solution to the broader community. With that said, there is a technical distinction between these two things (JSON and a Javascript object):

let jsonString = '{"key1":true,"key2":14,"key3":"test"}';

let js_object = {
key1: true,
key2: 14,
key3: 'test',
};

JSON is a data encoding format, and a Javascript object literal is actual code used to create an in-memory data structure. There are dedicated functions built in to the browser to change between the two:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

 _learnq is expecting a Javascript object rather than a JSON string. I hope that is helpful!

Badge

 _learnq is expecting a Javascript object rather than a JSON string. I hope that is helpful!

 

When I hand _learnq the object it fails if the keys are like ’key’ and works for “key”.

I do not believe this is my specific environment, it affects both Firefox and Chrome so I do not think it is a browser issue.

It might be worth looking into for future customers who are looking for a custom integration.

Reply