0

I am trying to call custom name method name in webapi class. I am using Postman and able call Get method but not CusActivity method. Postman is not throwing any error either.

What is wrong here?

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
    name: "ApiWithAction",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);



public class CusActivityController : ApiController
{
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    [HttpPost]
    public string CusActivityInsert(string userToken, string masterCustomerId, string activityText)
    {

    }

}

In POSTMAN

http://localhost:52957/api/CusActivity/CusActivityInsert

{
"userToken": "userToken1",
"masterCustomerId": "3440214",
"activityText": "ID01-Membership."
}

1 Answer 1

0

Your API only has one parameter in config.

You need change parameter of your action API to

public string CusActivityInsert(UserToken item)
{

}

with class

public class UserToken
{        
        public string userToken { get; set; }
        public string masterCustomerId { get; set; }
        public string activityText { get; set; }
}

If you want to keep current parameter, change PostMan API URL to

http://localhost:56433/api/CusActivity/CusActivityInsert?userToken=userToken1&masterCustomerId=3440214&activityText=ID01-Membership.

Sign up to request clarification or add additional context in comments.

2 Comments

How to allow multiple parameters in custom method? I need to pass multiple parameters
if you want to send JSON, need change to object in parameter

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.