1

I am working on an API that accepts a list of Objects as a parameter. This is the Api I am working with:

[HttpPost("PharmacySupply")]
        public async Task<List<PharmacyMedicineSupply>> GetPharmacySupply(List<MedicineDemand> medDemand)
        {
            SupplyRepo sr = new SupplyRepo();
            return await sr.GetPharmacySupply(medDemand);
        }

This is my model :

public class MedicineDemand
    {
        public string Medicine { get; set; }
        public int DemandCount { get; set; }
    }

I am passing this in swagger as parameter:

[
{Dolo,7},
{Cholecalciferol,9},
{Orthoherb,5},
{Gaviscon,2},
{Hilact,3}
{Cyclopam,1}
]

but the parameter is empty . It is showing a count of 0 while debugging. What am I doing wrong?

1 Answer 1

3

Try to add [FromBody] if you are testing using postman. (See [FromBody] documentation here)

 public async Task<List<PharmacyMedicineSupply>> GetPharmacySupply([FromBody] List<MedicineDemand> medDemand)

for test in postman you have to use

[
   { "Medicine": "Dolo", "DemandCount" : 7},
   { "Medicine": "Cholecalciferol", "DemandCount" : 9},
   ...
]

and if maybe you try for testing in swagger with this

[
   { "Dolo" , 7 },
   { "Cholecalciferol" , 9 },
   ...
]
Sign up to request clarification or add additional context in comments.

1 Comment

@sapter -- you asked this question 6 hours ago and I told you in comments to put [FromBody] in the parameters. Please don't ask the same question multiple times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.