I am trying to test an endpoint that takes two DateTimes as parameters by sending in requests via Postman. Here is the Controller method:
[HttpGet("metrics/user/{ownerId}/{startDate}/{endDate}")]
public async Task<IActionResult> GetUserCompletionRate(int ownerId, DateTime startDate, DateTime endDate)
{
//Check if user exists
var userExists = await unitOfWork.userAccountRepository
.UserAccountExists(ownerId);
//User doesn't exist
if (!userExists) return NotFound("Couldn't find user.");
//User exists
Double completionRate = await unitOfWork.completionLogEntryRepository.GetUserCompletionRate(ownerId, startDate, endDate);
return Ok(completionRate);
}
I've tried sending them in like this:
http://.../api/metrics/user/2/2018-7-23T00:00:00/2018-7-24T10:24:00
I then tried removing the parameters from the route and send it in like this:
http://.../api/metrics/user?ownerId=2&startDate=2018-7-23T00:00:00&endDate=2018-7-24T10:24:00
but nothing is working. I also tried declaring the dates in the route as {startDate:datetime} and nothing. How do I send in a DateTime object from Postman. I keep getting 404 Not Found errors.
MVC Controller, did you add anyRoutein the Controller? For this error, it is related with the URL and router, there is no problem inDateTime. Try request URL likehttp://.../metrics/user/2/2018-7-23T00:00:00/2018-7-24T10:24:00.