Kgn-web
Kgn-web

Reputation: 7555

Why getting null in the request parameter

Below is my API.

public HttpResponseMessage Delete(IEnumerable<int> customerIds)
{
    //api stuff
}

But when this API is hit I am getting customerIds as null.

This is how I am calling the API via Postman.

{
 "customerIds" : [69,50]
}

Content-Type = application/json

However, if I update the API as below, values are caught.

public HttpResponseMessage Delete(CustomerTO customerIds)
{
    //api stuff
}
public class CustomerTO
{
   public IEnumerable<int> CustomerIds
}

If I do so, I think its an overhead.

Any help/suggestion highly appreciated.

Upvotes: 1

Views: 252

Answers (2)

Jignesh Variya
Jignesh Variya

Reputation: 1919

The problem is in your post data object. You just need to pass an array [1,2,3,4] in your request data.

Upvotes: 1

Craig H
Craig H

Reputation: 2071

For the first one I think you might need to do it like this:

([FromBody] IEnumerable<int> customerIds)

Upvotes: 0

Related Questions