I’m looking for a working example of a Magento API-enabled module. How can I define it, write the code for it, and call it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A working config (in app/code/local/ModuleName/etc/ . I wrote mine into api.xml):
The PHP code (in app/code/local/ModuleName/Model/Api.php):
The PHP code to actually call the SOAP interface:
The result of running said script:
Some notes:
o Error: “Invalid api path.”
o Error: “Resource path is not callable.”
This means that Magento can’t call the method in the module.
You can use the system.log file to debug this. It will display one or more errors about how it couldn’t autoload the requested class from the calculated file-path.
o The module-config XML above will link this SOAP interface to a new item in the API permissions called “Get Info Test” under the “Customers” group. It will then be available to allow or deny on specific API users/roles.
o The value under /config/api/resources/customer/methods/info in the module-config XML is the internal method name of the method that should be bound to the SOAP resource-name. If they’re the same, then you may omit this.
o The value under /config/api/resources/customer (which is ‘ModuleName_Model_Api’) is the full class-name here because it’s obviously referring to my class, which isn’t part of Mage. If you’re trying to call an existing class within Mage, you can just use the shorthand notation (xxx/yyy, xxx/yyy_zzz, etc..).
o It’s only in the ACL part of the module-config that the value of the “module” attributes (<… module=””>) seems to matter. All the same, make sure it’s set properly (case doesn’t matter) everywhere. It might be that they just haven’t implemented it mainstream, yet, and to ignore it will just cause you problems later.
Dustin Oprea