简体   繁体   中英

Postman - how to post multiple entries

I am trying to add multiple entries into my database by using Postman.

My POST-method is made for single entries. Is there a way to do this without writing an extra method for the bulk import?

My bulk data looks like:

[
    { "Lastname": "Test", "Firstname": "Test", "Department": "IT", "Location": "", "Company": "Test"},
    { "Lastname": "Test2", "Firstname": "Test", "Department": "DEV", "Location": "", "Company": "Test"},
    { "Lastname": "Test3", "Firstname": "Test", "Department": "SD", "Location": "", "Company": "Test"}
]

My POST-API looks like this:

[HttpPost]
public async Task<IActionResult> Post([FromBody] Person person)
{
   ...
}

If your method is made for ONE entry, then the method can only accept one. You should create a new method that accepts a List of entries or an even easier option would be if you just insert all the data directly in the database and so no extra method is needed.

If the data you have is either in CSV or JSON format then you could use Postman Runner to send multiple requests one after the other to add the data into your database. You can also adjust the time between calls to not load your server with too many requests.

Here is an example on how to use Post Runner to make multiple calls with different params, https://stackoverflow.com/a/59457273/8568784

You will have to create a new POST method that accepts a collection of Person objects. Please refer to the code snippet below.

[HttpPost]
public async Task<IActionResult> PostAll([FromBody]List<Person> people)
{
    ...
}

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM