Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send enum value as body in Postman

Tags:

enums

postman

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.

like image 987
Asif Khan Avatar asked Sep 27 '17 04:09

Asif Khan


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).

like image 155
Jonas Bjelkerud Avatar answered Nov 20 '22 02:11

Jonas Bjelkerud


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"
}
like image 33
Lam Le Avatar answered Nov 20 '22 01:11

Lam Le


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 }

like image 2
Palash Roy Avatar answered Nov 20 '22 01:11

Palash Roy