Best Practices: How do I pass a mass collection, specifically ids, as API parameter?

I have a custom module, I added a list view action that calls a custom API.

I have a couple of options in mind:

1) call the API once per ID of the potentially hundreds of selected items,

2) call the API passing the mass collection as a parameter (can I do that? what kind of object do I get in the php to retrieve the ids from?)

3) call the API passing a long string of IDs to be parsed at the other end (how long can you go before the URL for the API call gets too long? Hundreds of IDs can make for a pretty long string....

Any suggestions on how to best approach this issue?



  • You would pass them as JSON. In PHP just create an array and then use json_encode() to convert the array to a JSON string. Then in your custom endpoint you just json_decode it back to a PHP array. 

  • Yes, but that would still make for a very long parameter.... I guess there is really no way around it.



  • Francesca Shiekh,

    Throwing some ideas your way, that might or might not work depending on the specifics of the scenario:

    1. What about using post instead of get, if it is a custom API? Even if not fully RESTful "compliant"? The limit of the request is much bigger
    2. Is there any option/alternative to pass the filter id or the filter conditions only to the backend? And then complete a backend logic to understand which ones are the records? You could do that in a queue
    3. If that's not possible as they might be user selectable records, if the user is selecting manually the ids, as you said, you could call the api at every UI interaction for every id

    Maybe let me know more and I will noodle on it a bit


    Enrico Simonetti

    Principal Technical Advisory Manager

    SugarCRM Inc

  • Yeah, what he said. Where's this long list of id's coming from anyway.  And what do you intend to do with them? 


  • The long list of IDs is coming from a list view, selected records' ids are passed to the list view action.

    I basically want to mass-execute some operation on a user selected subset of records.

    Full scenario:

    Custom module tracks Territory Assignments based on Country/State and other Account/Address data.

    A privileged user updates one or more Territory Assignment records to reassign/redesign how territories are assigned and to whom.

    They can then select multiple Territories from the List view of the Territory Assignment module and schedule the update  of the Accounts/Addresses to reassign the records. (Effectively what the ydo is Schedule a Job in the job_queue for later that evening)

    The privileged user could potentially choose as many territories as they want, even all of them.

    The List View Action needs the IDs of each of the selected Territories.

    What I have right now is in the controller, for each selected territory, run the API (with a single record ID) that sets up the scheduler for that individual territory.

    Select 100 territories and you create 100 scheduled jobs to be run at night at intervals.

    It works, and it segregates the jobs into multiple schedulers which hopefully avoids potential timeouts from massive updates, but it also means 100 API calls instead of just one with 100 IDs.