Malformed response from limelm.pkey.getDetails API callAnswered

Hello, 

We have recently encountered a problem we have not seen before.  Normally when we call 'limelm.pkey.getDetails' we receive it in the standard "JSON Response Format".  However with one particular License Key (so far) we are getting what appears to be a raw string.  

Here are the correct and incorrect versions for comparison (with the key details removed for privacy reasons):

CORRECT:

{ pkey:
   { key: 'XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX',
     acts: 1,
     acts_used: 1,
     created: '2020-09-17 11:11:47',
     total_deacts: 0,
     deac_limit: 'unlimited',
     for_tfs: 'false',
     allow_vm: 'yes',
     version_id: 7164,
     lc_allow_offline_act: 'inherit',
     lc_allow_deact: 'inherit',
     lc_self_deact_limit: 'inherit',
     lc_self_deact_limit_term: 'no-term-limit',
     lc_view_extradata: 'inherit',
     lc_view_fields: 'inherit',
     email: 'abc@abc.com',
     activations: { act: [Array] },
     features: { feature: [Array] } },
  stat: 'ok' }

 MALFORMED (as raw string):

{"pkey":{"key":"XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX","acts":1,"acts_used":1,"created":"2020-09-17 11:11:47","total_deacts":0,"deac_limit":"unlimited","for_tfs":"false","allow_vm":"yes","version_id":7164,"lc_allow_offline_act":"inherit","lc_allow_deact":"inherit","lc_self_deact_limit":"inherit","lc_self_deact_limit_term":"no-term-limit","lc_view_extradata":"inherit","lc_view_fields":"inherit","email":"abc@abc.com","activations":{"act":[{"id":15815176,"ip":"172.254.38.210","date":"2020-09-17 11:13:30","type":"windows","extra_data":"Abc Anderson (Desktop:abc@abc.com:ABC Design Group Architects:xyy7ZjdiM+PiPawa5PUb9LIAy6y8hsuepn5VxtZ0cNw="}]},"features":{"feature":[{"name":"BillingStartDate","value":"2020-09-17 11:11:47"},{"name":"ExpiryDate","value":"2020-11-22"}]}},"stat":"ok"})

This is a rather urgent issue as our License management system is failing due to this data not being the expected JSON format.

Thank you.

, edited

JSON is just a string. Yes, we strip out whitespace (it's an unnecessary waste of space -- any proper algorithm can parse JSON with or without "decorative" whitespace). What exactly is the problem? Are you not reading the headers correctly? Are you not parsing it correctly? Are you not making the request correctly?

Here's how to make a correct JSON request: https://wyday.com/limelm/help/api/response.json/

Did you forget about nojsoncallback?

As always, more information is needed: I'm having a problem, how do I solve it?

, edited

I think the issue here is the end ")" in the MALFORMED returned string. Even though some json processors think it is a valid json stream but not javascript/nodejs.  JSON.parse() will throw an error. SyntaxError: Unexpected token ) in JSON at position 786 (edited). Just wondering how the trailing ")" got in from your end at the first place.  Thank you! Simon

We can't reproduce this.

Did you forget about nojsoncallback?

As always, more information is needed: I'm having a problem, how do I solve it?

As always, more information is needed: I'm having a problem, how do I solve it?

What other information would you like?  

We use the 'nojsoncallback' in some other calls to the API but not this one as it never mattered - everything has worked as expected with thousands of other keys processed (which store data the same way).  

Does every call to the API require a 'nojsoncallback' to be set?  

What is the default if you don't explicitly specify the 'nojsoncallback' when making an API call?  

Furthermore, what would setting or not setting 'nojsoncallback' have to do with a bracket at the end of the JSON string?  

The string I posted earlier (I marked as Malformed in the message) is exactly what we get back from the LimeLM API call ('limelm.pkey.getDetails').  If we remove the trailing ")" it parses to JSON successfully.

We can provide the key to you and you can see for yourself - I didn't want to put it here for security reasons, but if you'd like I could send it to you some other way in case there is something for you to debug there. 

Answer

Does every call to the API require a 'nojsoncallback' to be set?  

Yes:

Callback Function

If you just want the raw JSON, with no function wrapper, add the parameter nojsoncallback with a value of 1 to your request.

To define your own callback function name, add the parameter jsoncallback with your desired name as the value.

nojsoncallback=1 -> {...}
jsoncallback=wooYay -> wooYay({...});

What is the default if you don't explicitly specify the 'nojsoncallback' when making an API call?  

Again, from: https://wyday.com/limelm/help/api/response.json/

When a request is successful, the following JSON is returned:

jsonLimeLMApi({...});
, edited

My apologies for any confusion, now I think I understand what our issue is.  I had read the info about the  nojsoncallback  on the site already however I wasn't fully grasping it's intent.

Thanks for the reply, Just a quick question: if we create our own callback function, how does it get triggered?

A thousand ways to skin that cat: https://en.m.wikipedia.org/wiki/JSONP

These days, easier and safer to parse using built in functions and take some specific action.

Thanks so much for the support and help. Really appreciate it. 

No problem.