Extracting Model Size through API


I have used the scripts set out here: Solved: API Python Workspace and Model IDs - Anaplan Community to successfully extract a basic model and workspace list.  Thanks to @abhay.kanik for the good start.


I have added the ?modelDetails=true switch to the Model JSON so the API send more details about models.  The JSON then contains the following information:



I can refer to and extract lastModified and ActiveState with no issues.  However, when I try to include the model 'memoryUsage' in my export Python returns a "KeyError".


The code I have modified is:

for mdl in model_json['models']:
model_writer.writerow(['{}'.format(mdl['id']), '{}'.format(mdl['name']), '{}'.format(mdl['activeState']), '{}'.format(mdl['memoryUsage']), '{}'.format(mdl['lastModified']), '{}'.format(wsp['id']),'{}'.format(wsp['name'])])


If I remove the memory usage request the script runs fine and gives me the other results.


Any suggestions on what I may be doing wrong here?

Best Answer

  • M.Kierepka
    Answer ✓
    I believe you are doing everything correctly, it's just Anaplan's API that doesn't send you required data for all models. I checked on my side, and when I use "?modelDetails=true", some models indeed don't return size info. I couldn't find any pattern - I thought it might be unavailable for archived or old models, but no - it doesn't depend on state nor date of creation.
    What you can do for now is replace "mdl['memoryUsage']" with simple check: mdl['memoryUsage'] if mdl['memoryUsage'] else ''


  • Thanks, @M.Kierepka, I couldn't get your solution to work, however, I applied a different method to capture when the data was missing and it worked.  Thanks for pointing me in the right direction.