I'd like to setup Magento so that if I make a request with an URL such as: http://mymagento.com/api/storeconfig (actual url format not important)

would return json with the data requested. How can I achieve this? Here's how I'm retrieving the data:

public function getStoreSettings()
    //this successfully retrieves the value of my custom settings property
    $my_property= Mage::getStoreConfig('my_module/my_settings/my_property', 'default');

    $data = array('my_property'=>$my_property);
    $json = Mage::helper('core')->jsonEncode($data);

    //return json here

Where would the right place to add this code? How can I map an URL to call this function and return the response as json? I appreciate if anyone could point me in the right direction!

1 Answer 1


After lots of playing around with Magento, trying to figure out all the magic going on, I found a solution to my problem, and am adding a solution for those who may come across the same task.

1 - Go to your app/etc/modules/YourPackage_YourModule.xml This is what I have:



this will create a route for http://yourmagento.com/yourmodule/yourcontroller/youraction

2- Go to app/code/community/YourPackage/YourModule/controllers/ Create your YourController.php. This is mine:


class YourPackage_YourModule_YourController extends Mage_Core_Controller_Front_Action

    public function indexAction()
        $response = array('my_key'=> 'my_value');



There's a lot of magic going on with the naming conventions, for a more in-depth walk-through, check out Magento for Developers: Part 3 - Magento Controller Dispatch

Your Answer

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

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