Why do I get the error in the screenshot below when attempting to call a Web API method that takes a enum as an input parameter? How do I resolve this?
It appears like the messageDestinationType
is always null no matter what I do...
I would prefer to keep the input type as an enum. I am newish to using web apis and can't understand how this is so difficult when a WCF handles this scenario perfectly
[JsonConverter(typeof(StringEnumConverter))]
public enum MessageDestinationType
{
None = 0,
[EnumMember(Value = "SMS")]
SMS = 1,
[EnumMember(Value = "Email")]
Email = 2,
PushNotification = 3,
UXP = 4,
IntermediaryApp = 5,
YouthApp = 6
}
[HttpPost, Route("ReadClientMessagesC")]
public IHttpActionResult ReadClientMessagesC([FromBody]MessageDestinationType messageDestinationType)
{
var request = new ClientInboxRequest
{
Gcn = Gcn,
ClientIpAddress = ClientIpAddress,
CallingApplication = CallingApplication.Name,
CallingApplicationVersion = CallingApplication.Version,
CookieString = CookieString,
HasPbUk = HasPbUk,
HasIamIms = HasIamIms,
HasPbZa = HasPbZa,
HasSps = HasSps,
HasWiUk = HasWiUk,
HasWiZa = HasWiZa,
LinkedGcns = LinkedGcns,
RequestId = RequestId.ToString(),
SsoProfiles = SsoProfiles.Select(x => x.Name).ToList()
};
MessageDestinationType messageDestination = (MessageDestinationType)messageDestinationType;
return Ok(ClientMessageCenterHelper.ReadClientMessagesA(Gcn, messageDestination, request));
}
Error message: { "Message": "The request is invalid.", "MessageDetail": "The parameters dictionary contains a null entry for parameter 'messageDestinationType' of non-nullable type 'API.Domain.ClientMessageCenter.MessageDestinationType' for method 'System.Web.Http.IHttpActionResult ReadClientMessagesC(API.Domain.ClientMessageCenter.MessageDestinationType)' in 'ID.ClientMessageCenter.Controllers.ClientMessageCenterController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter." }