https://discord.umbraco.com logo
#help-with-umbraco
Custom API controller always returns 404 ??
# help-with-umbraco
s

steffennielsen_84056

02/07/2024, 10:59 AM
Hi folk, I have a small problem, that i can't seem to figure out. My problem is, that i have created a simple controller in the backoffice, that uses the UmbracoApiController, so that the controller and endpoint should be available at host/umbraco/api/controller/endpoint. But somehow i keep getting a 404 response. I have done nothing special in the code, and i have followed the official documentation, but still the same issue occures. my class looks like this and should be available at /umbraco/api/custom/isalive public class CustomController : UmbracoApiController { public bool IsAlive() { return true; } } Any idea, as to what might be the problem?
s

Sebastiaan

02/07/2024, 11:38 AM
There's a convention as well to start the method name with
Get
, so that the route is available using a
GET
request. If you don't want to name it
GetIsAlive
then you can decorate the method with a
[HttpGet]
attribute.
s

steffennielsen_84056

02/07/2024, 11:53 AM
I found the solution. There was a metadata issue in my project, so after doing a clean repo clone and inserting the controller again, the issue was gone. I don't hope i will experience this again in the future. 2 hours down the drain.
s

Sebastiaan

02/07/2024, 12:11 PM
Welcome to the life of a software developer 😉
s

skttl

02/07/2024, 12:26 PM
"I don't hope i will experience this again in the future" - you will... trust me 🙂