Deleting multiple records

Sorry if this is a very basic question; I’m very new to APIs. I have an API call that deletes a record, but it only deletes one record at a time, and then I have to manually add the next id. I have a long list of IDs. :frowning: How can I loop through the delete routine? Do I do that in Flows? I tried to create a flow, and it works if I add only one id but it doesn’t work for 2 or more ids. Are you able to share a screenshot of how such a flow is supposed to look like? I tried to find a tutorial on how to do it but didn’t manage to.

i always pass the ids in the string format … while deleting i separate the each ids with that string using the ( , comma separate) and run the for loop

i know it’s not the right way but still work for me

in the code i do this :

     $idString = $request->query('id'); // "1,2,3"

    // Convert comma-separated string to array
    $ids = explode(',', $idString); // ['1', '2', '3']

    // Optionally convert to integers
    $ids = array_map('intval', $ids); // [1, 2, 3]

This is entirely dependent on the implementation of that particular API. Not all API are the same and accept a comma separated list of values in a query param.

Hey @olgakalach :waving_hand:t2:

Welcome to the Postman Community :postman:

It sounds like using a data file and the Collection Runner with help here.

You have a list of IDs already, what format are those in?

If you create a CSV file, add a heading as the variable key, this is referenced in the request, and then place all your IDs under that header.

You can then replace the hardcoded Id in the request with the variable name from the data file {{csv_heading_name}}.

Using the Collection Runner, it will iterate through the list one by one and delete the records.

1 Like

Thanks a lot, Srushti and Danny. My ids look like this: 3aa023a5-9b52-4420-9ba3-68f1d84b16dk. I will give a try to your suggestions over the next few days. I appreciate your help!

What does the full request URL look like?

Or the part of the request that takes the id?

It looks like this: DEL {{baseUrl}}/coursereserves/courselistings/3aa023a5-9b52-4420-9ba3-68f1d84b16dk but that deletes only one record at a time.

@olgakalach, Welcome to the Community :slight_smile:

Yes you can try the options suggested above. If you haven’t checked with your developer (if it’s an internal API), ask if there’s any other endpoint for deleting multiple entries. Or if there’s any API documentation, it’s worth checking again :slight_smile:

If you have tried these already, then “Data driven” is the simplest way!

1 Like

You would have your datafile of ids in a csv file:

You would then have your request but with a variable placeholder in the URL:

Open the Collection Runner and add the datafile, this will show you a preview:

Then Run the Collection and the request will iterate through the datafile of ids

That worked! Thank you so much, Danny!!!

1 Like

I learn something new too thank you!! @danny-dainton :+1: :hugs:

1 Like