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?

thanks,

Francesca

Parents Reply Children
  • 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.

    FrancescaS