I am new to Magento and want to know how to write Rest web services with PHP. Please suggest me with any material or example with full explanation because i gone through many, but couldn't find a good one which is working. I can also say that i don't know how to execute that. please give me a full explanation with example. Thanks in advance :)


There is a good solution using this library PHP.

Magento Client Library For PHP



The following example returns a list of products with SKUs that start with "123":

use Magento\Client\Xmlrpc\MagentoXmlrpcClient;

$client = MagentoXmlrpcClient::factory(array(
    'base_url' => 'http://magentohost',
    'api_user' => 'api.user',
    'api_key'  => 'some.private.key',

$filters = array(
    'sku' => array('like' => '123%'),

$result = $client->call('catalog_product.list', array($filters));


The following example returns a list of products:

use Magento\Client\Rest\MagentoRestClient;

$client = MagentoRestClient::factory(array(
    'base_url'        => 'http://magentohost',
    'consumer_key'    => 'abc123...',
    'consumer_secret' => 'def456...',
    'token'           => 'ghi789...',
    'token_secret'    => 'jkl012...',

$result = $client->get('/api/rest/products')->send()->json();
  • how can I display my API values as a table format. my post : magento.stackexchange.com/q/209734/57334 – zus Jan 18 '18 at 5:52
  • I am used to WooCommerce and Shopify where we only need a key and secret, how do we get tokens? – user2924019 Jan 23 '19 at 17:31
  • 1
    You can use a software called Postman to do the first request just to get these tokens once. After that, you won't need to request again. – Rafael Corrêa Gomes Jan 23 '19 at 17:42
  • @RafaelCorrêaGomes I just realised I've been watching your YouTube video about authentication. Do you know if I can use the same token forever? My system takes orders every 10 minutes and puts them into a WMS. Can I just use that same token? – user2924019 Jan 30 '19 at 17:42
  • @user2924019 yes, the token can be used forever or until you invalidated it. – Rafael Corrêa Gomes Jan 30 '19 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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