Hello,

I would like to use the Web service client module to use a REST API for Magento (http://www.magentocommerce.com/api/rest/introduction.html). I'm trying to call it from a Drupal website and I was wondering if I could create a submodule of wsclient for this instead of reinventing the wheel and creating one from scratch. I found the following while reading through the readme file and I was wondering if this applies to my case.

***
Usage for developers
--------------------

* You can create web service descriptions in code, see for example
wsclient_examples.module
* You can easily invoke web services by loading the description and executing
an operation (the operation name can be used a dynamic method name):

$service = wsclient_service_load('google');
$result = $service->translate('Hallo Welt', 'de|en');
***

I have spent the past hour or so reading all the feature requests in the issue queue I could find about REST and OAuth or basic authentication and I have a few questions.
First, how would I implement authentication when calling the Magento REST API? Would I be able to implement some sort of Single Sign-On functionality? So, in other words, if I used the wsclient_examples module as a basis for a module of my own, how would I change the code in order to use the Magento REST API with authentication (please see authentication details for Magento at the bottom of this page: http://www.magentocommerce.com/api/rest/introduction.html).

The workflow would be this:

Visitor accesses Drupal website -->
Clicks "Buy Product" -->
Magento product page opens -->
After checkout process is finished, Magento user is created on the Magento site -->
Magento calls Drupal web service to create a Drupal user OR Drupal automatically syncs users at a specified interval of time.

Scheduled synchronisation considerations:
- sync Products - each product on the Magento side would have a representative node of content type Magento, let'say
- sync Customers - each Magento customer would have a representative user in Drupal

I have a test site working with Magento REST API with dummy products. It's http://bani.co and according to the top link for the REST API, the resources can be found at http://bani.co/api/rest. Credentials to use:
Name = Drupal API user
Key = 7c3262c82cff08ebc224adef247c2dcc
Secret = c7e3e862a28dfc4f1839a1f54c614e42

If I created a module of my own to use the hooks in this module, what hook would I have to use? wsclient_endpoint_types? Are there others?

Also, I tried creating a web service description with a URL for a Magento test site (http://bani.co/api?wsdl) but got the following message:
"Error parsing the WSDL file: SOAP-ERROR: Parsing WSDL: Couldn't find in 'http://bani.co/api?wsdl'"
I created a SOAP User and SOAP Role on the Magento side that allows for resources to be accessed. Is the above message related to the fact that I haven't used authentication with the web service description? If so, would you be so kind and let me know how I can used authentication or solve the error, for that matter?

One last question. After creating a module, would I be able to still integrated it with Rules or cron (I would imagine so, just looking for confirmation)? For example, to run the update products requests at certain times or after such and such event?

Any help would be greatly appreciated!
Thank you,
Andrei

Comments

andreic’s picture

In this module (wsclient) it says

"wsclient_rest.module depends on http_client.module."

and on the http_client module it says

"Comes with support for authenticating with OAuth.module version 3.x for easy to access OAuth-protected resources."

That's basically the gist of my issue: I'm trying to use wsclient to consume the Magento API using authentication with oAuth but I can't find any helpful documentation.
Would someone please point me in the right direction?

Thank you,
Andrei