Replace all options in optionlist via API
AnsweredI will be setting up a nightly PHP script to update the options in our option lists. One of them is a list of employees where the label is an employee name and the key_value is an employee ID number. This list is managed by admin users on our 3rd party system outside of iformbuilder. My goal is to take any changes that were made in our external system and update our iformbuilder lists nightly. In looking through the v6 API docs, I do not see any sort of replace() method that would replace all existing options with a new set. As far as I can tell, the best way is to send a delete request on the option collection without sending any IDs to delete all the options, then send a second request to create the new options.
Why not just update individual options? First of all, it would use more API calls. I would have to use one call to get the existing options. Then I would have to write a bunch of code to compare them all to the current list on our side. There could potentially be new options, deleted options, or existing options updated. So that would be four API calls and a lot more programming to accomplish the same thing. Using one request to delete all options then one request to add new options is much simpler to program is less error-prone. The problem is that it still uses two API calls to accomplish one list update. Updating lists is basically the only thing I will be using the API for, so my 10,000 requests are essentially cut in half. This becomes a problem, for example, if we get up to 170 lists that need to be updated daily (which is possible in the near future). 170 lists * 30 days is 5100 API calls. But if I have to use two calls for each list, it puts me over 10,000 for the month. If I could replace all the options in a list with one API call, that would be much cleaner. Maybe there's already a way to do that and I'm just missing it.
Along the same lines, is it OK to update options by deleting and then re-creating them as long as the key_values are the same? For example, say I have this option: key_value = 1234, label = "First Last". Then I fill out a form and select that option. Then using the API, I delete that option and create a new option with the same key_value but a new label. When I re-open that saved form, will that option still be selected since the key_value is the same? Or is it saved by Option ID and the previous selection would be lost?
-
Hi Kyle, you are correct with your assumptions about v60, you have to delete everything if you want to load the entire list content over again (2 requests). You won't cause any harm if when you create the list again, the original options have the same keys as before you deleted.
If you are really concerned about usage, then you may consider using the 5.1 APIs instead for your option list updates as the update list request requires that you send in all the content and our server code blow the existing options away for you.
Hope that helps,
Tony -
OK, I'll try using the 5.1 API instead. When I tried it before via the PHP sdk, it was creating a copy of the list ending in "_1" instead of updating the existing list. It looks like it might be a bug in the sdk where the ZCOptionList edit() method is sending a POST request, and the API docs say it should be a PUT request. POST is for creating a new list, so I believe the edit() method was incorrectly creating a new list with the same name).
Our growing plan migration is scheduled for tonight, so I will give it a try tomorrow. I noticed in the v60 API, each call is limited to 1000 items. The employee list I want to update has about 1100 items. With the 5.1 API, can I send all of them in one call, or does it also have the 1000 item limit? Thanks.
Please sign in to leave a comment.
Comments
3 comments