How to get value of core_config_data eg. general/region/state_required
using Magento soap api?
2 Answers
Create A Custommodule:
Api File(Api.php)
<?php
class Amit_Customapi_Model_Api extends Mage_Api_Model_Resource_Abstract
{
public function myregion()
{
$countryList = explode(',', Mage::getStoreConfig(general/region/state_required));
return $countryList;
}
}
and etc/api.xml is
<?xml version="1.0"?>
<config>
<api>
<resources>
<customapi_api translate="title" module="customapi">
<title>Myapi</title>
<acl>customapi/api</acl>
<model>customapi/api</model>
<methods>
<myregion translate="title" module="customapi">
<title>Require Region</title>
<acl>customapi/myregion</acl>
</myregion>
</methods>
</customapi_api>
</resources>
<acl>
<resources>
<customapi translate="title" module="customapi">
<title>Customapi</title>
<sort_order>2000</sort_order>
<myregion translate="title" module="customapi">
<title>Require Region</title>
</myregion>
</customapi>
</resources>
</acl>
</api>
</config>
You can access by below url
SOAP
$client = new SoapClient('http://yourhost/api/soap/?wsdl');
$session = $client->login('******', '******');
$date = $client->call($session, 'customapi_api.myregion');
XML-RPC
$client = new Zend_XmlRpc_Client('http://yourhost/api/xmlrpc/');
$session = $client->call('login', array('******', '******'));
$date=$client->call('call', array($session, 'customapi_api.myregion'));
Edit: Full module
app/code/local/Amit/Customapi/etc/
File:config.xml and
code of this file:
<?xml version="1.0"?>
<config>
<modules>
<Amit_Customapi>
<version>0.1.0</version>
</Amit_Customapi>
</modules>
<global>
<helpers>
<customapi>
<class>Amit_Customapi_Helper</class>
</customapi>
</helpers>
<models>
<customapi>
<class>Amit_Customapi_Model</class>
<resourceModel>customapi_mysql4</resourceModel>
</customapi>
</models>
</global>
</config>
-
Thanks Amit for such a detailed answer. I tried creating custom module as you mention (Also added blank Helper/Data.php and assign role 'Required Region' to user ) but it says 'Access Denied'. I don't know what went wrong– SandeshCommented Aug 22, 2014 at 10:30
-
I need to create helper class.then reset admin permissio– Amit Bera ♦Commented Aug 22, 2014 at 10:52
-
What I did is created
Helper/Data.php
with<?php class Amit_Customapi_Helper_Data extends Mage_Core_Helper_Abstract { }
But still it says 'Access Denied'. What do you mean by 'RESET admin permisssion'– SandeshCommented Aug 22, 2014 at 10:59 -
If
Webservice - SOAP - Resource Roles
selected toAll
then output is correct, but ifResource role
selected toCustom
and checkedRequired Region
then output isAccess Denied
. Any Idea how to fix this?– SandeshCommented Aug 22, 2014 at 12:37 -
@AmitBera My soap return value as objects how to return as XML? my code : justpaste.it/58dm2 can you pls help me?– zusCommented Nov 15, 2018 at 4:41
You can't.
But what you can do is create your own SOAP API callable function/extend SOAP API.
The (current) details are published here: http://www.magentocommerce.com/api/soap/create_your_own_api.html
Then you can make Magento do what you need.
There may be a module out there already that exposes parts if not the whole of core_config_data but it's unlikely!
The Core Config Data is a odd one to expose on the API as it contains most of the keys to the empire. So if you do extend to get data from here, make sure it's read only and restrict it to a set of keys. Say general/region/*