0

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)
{
   ...
}
KJSR
  • 1,679
  • 6
  • 28
  • 51
Henning
  • 421
  • 2
  • 11
  • 22
  • 1
    Probably worth a read: [Running multiple iterations in Postman](https://learning.getpostman.com/docs/postman/collection-runs/running-multiple-iterations/) – Diado Nov 19 '19 at 14:13
  • I tried that, but with each iteration only the first record of my bulk data is created. – Henning Nov 19 '19 at 14:28

3 Answers3

0

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.

ziga1337
  • 144
  • 1
  • 10
  • That's correct. But is there perhaps a way with Postman to add the data as a mass import? Maybe with a script or something? – Henning Nov 19 '19 at 14:09
0

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

codeblooded
  • 320
  • 1
  • 9
0

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.

Mahesh Nepal
  • 1,385
  • 11
  • 16