Tom
Tom

Reputation: 8681

Unable to test the create webapi method using Postman

I need to test my WebAPI create method using postman. Currently the model passed to the create method is null. I am trying to pass JSON values to it. Not sure what I a m doing is wrong

        [HttpPost]
        [SkipTokenAuthorization]
        [Route("api/manager/create")]
        public IHttpActionResult Create(PersonViewModel model)
        {
            var mgrService = GetService<MANAGER>();
            var manager = new MANAGER();
            if (model != null)
            {
                manager.PERSON.FIRST_NAME = model.FirstName;
                manager.PERSON.LAST_NAME = model.LastName;
                var mgr = new MANAGER();
                mgr = mgrService.Create(manager);
            }
            return Ok(manager);
        }

I have selected the option raw and text as JSON in postman and written the following JSON

{
   'FirstName' : 'Ralf'
   'LastName' : 'Lauren',
   'Id'     : “0”
 }

ViewModel

 public class PersonViewModel
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Id { get; set; }
  }

Upvotes: 0

Views: 184

Answers (1)

IMujagic
IMujagic

Reputation: 1259

try this JSON:

 {
    "FirstName": "Ranjit",
    "LastName": "Menon",
    "Id": 0
}

Make sure you are sending a valid JSON. There are plenty of online JSON Validators, there you can check if your "raw" Postman entry is valid.

https://jsonlint.com/

Upvotes: 4

Related Questions