Web API key creation ignores date type custom featureSolved

I'm writing a private remote script to create keys in Python, matching the style and methods of the PHP examples. In the portal I have defined two custom fields:
a) ExpirationDate (type=date)
b) FeatureName (type=string)
 

My script sets these two parallel string lists of equal length in lime_api.GeneratePKeys():

      feature_names =['ExpirationDate',                  'FeatureName'],    
      feature_values =['2021-06-30 12:00:00',          'Professional'],

The XML return I get back is:

<?xml version="1.0" ?>

<rsp stat="ok">

       <pkeys pages="1" total="1">

               <pkey acts="1" acts_used="0" allow_vm="no" created="2020-10-19 13:43:40" deac_limit="unlimited" email="joe.bloggs@somewhere.com" for_tfs="false" id="4227480" key="XXXX..." total_deacts="0" version_id="7483">

                       <features>

                               <feature name="FeatureName" value="Professional"/>

                       </features>

               </pkey>

       </pkeys>

</rsp>

I am unable to push the ExpirationDate, it always stays blank/ignored in the portal, and only the single string-type custom feature is returned on search. I've checked the exact date or date-time format, and copy-pasted from other manually generated keys, without success. Any hints what I'm doing wrong please?

Answer

More important is how you actually send the data to LimeLM. The feature names / values for each separate name value pair should be separate parameters. See the docs.

E.g.:

? ... feature_name[]=ExpirationDate&feature_value[]=2021-06-30 12:00:00&feature_name[]=FeatureName&feature_value[]=Professional

Result: Issue was on my side in how post was specified. This is NOT a LimeLM bug. Thank you for the hint (spotted the missing "[]" in post string)!

We were passing a python dictionary with key entries containing lists, and python requests.post(data=post_data) was incorrectly formatting this post data causing the key overwrite, so only one element of the list was working. It has nothing to do with custom fields with date type (per subject title). In case anyone hits something similar, here is a PYTHON code snippet of our solution, which pre-filters the dictionary and inserts the missing "[]" for list items, then uses the alternative "params" argument in posting:

       import requests       
       post_data {...} # dictionary
       params_str = ''
       for key, value in post_data.items():
           if type(value) is list:
               for item in value:
                   params_str += key + '[]=' + item + '&'
           else:
               params_str += key + '=' + str(value) + '&'
       req = requests.post(url, params=params_str)

Also having this issue, and params is no longer supported:

https://wyday.com/blog/2021/limelm-price-changes-and-stricter-web-api/

How can I format this request as JSON, for use with requests.post(data=post_data)?

This is what I tried.

post_data = {'format': 'json', 'api_key': '…', 'version_id': 9999, 'method': 'limelm.pkey.generate', 'num_keys': 1, 'num_acts': 1, 'email': 'me@email.com', 'feature_name': ['feature1', 'feature2'], 'feature_value': [True, True]}

requests.post(wyday_url, data=post_data)

This results in only feature2 being recognised.

Probably whatever “magic” your HTTP post library is using is mangling things.

Form the strings manually. Then, once you get that working, work backwards and fix or replace whatever magic HTTP post library you’re using.

Thanks Wyatt.

For anyone else having this issue, one solution was to turn that dictionary into a list, and include the `[]` brackets in the argument name.

data = [
   ("method", "limelm.pkey.generate"),
   ("format", "json"),
   ("api_key", wyday_api_key),
   ("version_id", wyday_version_id),
   ("num_keys", 1),
   ("num_acts", 1),
   ("email", email

   ("feature_name[]", "feature1"),
   ("feature_value[]", 1),
   ("feature_name[]", "feature2"),
   ("feature_value[]", 1),
]

requests.post(wyday_url, data=data)
, edited