I've been tasked with recreating an API within our Craft 2.X installation. For whatever reason, the API specifies the resource it is requesting with the query string parameter action. For example, instead of baseurl.com/api/users, they have it set up as baseurl.com/api?action=users

I thought I'd be okay if I used the ElementAPI plugin, set up an endpoint, and parsed the query string to figure out which set of elements to return as JSON. But it turns out that action is a very special query string parameter to Craft. When it receives a request containing action, Craft goes looking for a controller that will match it. I believe that Craft uses this pattern to handle a lot of basic business logic for the CMS. This seems like a very difficult branch of code to subvert -- this check fires before just about everything else.

Things I've tried, without luck:

  • Changing the action trigger in the config file, in hopes of removing the magic from "action".

  • Setting up a route in routes.php that goes directly to a plugin. Didn't work because UrlManager only fires after processActionRequest, which is the source of the error.

  • Asking the people who maintain the API to change the endpoints they're looking for.

Assuming that I'm required to use "action" as a key in my query string, how can I accomplish that in Craft 2?

Thanks in advance for any advice.

1 Answer 1


I think you're going to have to go up the chain to where the request starts - i.e. the server config. Rewrite all urls matching api?action=... to somewhere else. If you're using nginx it'd be something like

rewrite /api/$arg_action last;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.