I'm trying to create my first Alchemy plugin and I keep getting a 404 error when calling a method on the controller. I'm using the JavaScript proxy that gets generated automatically, but the URL that it contacts returns a File Not Found error (status 404).
This is my controller:
[AlchemyRoutePrefix("AddUserController")]
public class AddUserController : AlchemyApiController
{
[HttpPost]
[Route("NewUser")]
public string NewUser(string name, string description)
{
...
}
}
And this is the command that calls it:
Alchemy.command("${PluginName}", "AddUserByName",
{
execute: function()
{
....
Alchemy.Plugins["${PluginName}"].Api.AddUserController.newUser(username, fullName)
.success(function(response) {
console.log("Added new user: ", response);
})
.error(function(response) {
console.log("Error: ", response);
});
....
}
});
It ends up requesting the URL '/Alchemy/Plugins/Add_User_By_Name/api/AddUserController/NewUser' which then returns the 404 status code. That URL seems correct, according to the documentation.
What I've tried so far:
- Changing the controller to use HttpGet instead of HttpPost.
- Removed the AlchemyRoutePrefix attribute. The URL that it tried to contact changed as expected, but still gave a 404.
- Double-checked that I'm using the right JavaScript method (verified using code completion from within the browser console).
- Looked at the Big Box o' Samples to find an example that uses a controller. It doesn't seem to have one.
- Adding the parameters as route variables (e.g. Route("NewUser/{name}/{description})"). Still got a 404 but I also noticed that backslashes were changed to forward-slashes. Update: It turns out that this does work if no parameters are empty and you don't use any backslashes. Unfortunately, I need to support both of those things.
- Changing the method arguments to a single POCO class (UserModel with 2 string properties). This results in a 500 error instead (suggesting that the routing perhaps does work) but there were no details available anywhere (in the error message or in the server logs). It just said "An error has occurred.".
- Added the
[FromBody]
attribute to the name and description arguments in the NewUser method. This resulted in the same generic error as #6.
Does anyone have any ideas on why the routing seems to fail?