23.02.2015 Views

www.it-ebooks.info

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The Magento API<br />

• Consumer Key: This is a unique value used to identify a user w<strong>it</strong>h Magento.<br />

• Consumer Secret: This is a secret used by the customer to guarantee the<br />

ownership of the consumer key. This value is never passed in the request.<br />

• Request Token: This value is used by the consumer (application) to obtain<br />

authorization from the user to access the API resources.<br />

• Access Token: This is returned in exchange of the request token and on<br />

successful authentication.<br />

Let's proceed to register our application by going to System | Web Services |<br />

REST - OAuth Consumers and selecting Add New in the Admin panel:<br />

One important thing to notice is that a callback URL must be<br />

defined, to which the user will be redirected after successfully<br />

authorizing the application.<br />

Our first step is to learn how to get this session token ID on each of the available<br />

API protocols.<br />

To get session token ID in XML-RPC, we need to execute the following code:<br />

$apiUser = 'username';<br />

$apiKey = 'password';<br />

$client = new Zend_XmlRpc_Client('http://ourhost.com/api/xmlrpc/');<br />

// We authenticate ourselves and get a session token id<br />

$sessionId = $client->call('login', array($apiUser, $apiKey));<br />

[ 170 ]<br />

<strong>www</strong>.<strong>it</strong>-<strong>ebooks</strong>.<strong>info</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!