Send enum value as body in Postman

Viewed 33988

I'm trying to call my API using postman, but the problem I'm facing is my API is using PUT method which takes enum object as a body.. How can I send enum in postman.. please help.

export enum TestStatus {
    allCandidates,
    completedTest,
    expiredTest,
    blockedTest
}

this is my enum , I'm using Angular 2.

3 Answers

With a method taking the enum as the body, the enum value needs to be entered without curly brackets, simply

"expiredTest"

or

2

directly in the Body tab (with raw and JSON(application/json) and an ASP.NET Core backend).

Providing you have a method that takes [FromBody]TestStatus status as a parameter.

  • Click on Body tab and select raw, then JSON(application/json).
  • Use this Json:

    {
        "TestStatus": "expiredTest"
    }
    
  • Send!

I think above is your case as you stated: "take enum object as a body". Below are some more trivial ingredients:
If you have a parameter like [FromBody]MyClass class and its definition as

public class MyClass
{
    public Guid Id { get; set; }
    public TestStatus ClassStatus { get; set; }
}

Then you modify your Json as:

{
    "Id": "28fa119e-fd61-461e-a727-08d504b9ee0b",
    "ClassStatus": "expiredTest"
}

Just pass 0,1,2... interger in the json body to pass enum objects. Choose 0 if required to pass the first enum object. Exmple: { "employee": 0 }

Related