FAQ

General

What is the difference between Simple and OAuth version?

Both version support the same features.

OAuth version: you need to get an access token, and you should send it in every request to identify the user.

Simple version: you need to send a secret key in every request Header(this is the same for every user and you can set it on the admin site)

What is this extension?

The Opencart REST API extension adds the ability to remotely work with the OpenCart via the REST API.

RESTFUL API allows communication between a device or application with opencart.

If you develop Android / Windows 8 / IOS apps, this is a great extension for you.

REST ADMIN API

For eCommerce inventory & warehouse management systems
List / create / edit / delete products, categories, options, images,etc.

Opencart Shopping Cart REST API

Supports shopping cart functionality
Best solution to build Opencart Mobile App .

Where can I try Opencart REST API extension?

You can try all Opencart Shopping Cart REST API here: demo
You can try all Opencart REST ADMIN API services here: demo

How do I download Opencart API extensions?

In order to download Opencart API extension:
  1. Go to the Opencart API extension product page and click “Add to cart”.
  2. Go through the checkout process.
  3. After success payment, you will receive an email with the download link.

What is the difference between Opencart Shopping Cart REST API and Opencart REST ADMIN API?

If you need shopping cart functionality, please check our Shopping Cart REST API
It supports the full checkout process, and it creates an order at the end of the process.

Shopping Cart REST API demo: http://api.opencart-api.com/demo/shopping-cart/

If you need administration functions, stock management, product management, etc, please check our REST ADMIN API
REST ADMIN API demo: http://api.opencart-api.com/demo/admin/

Compare Opencart REST Api versions

Is Opencart REST API compatible with my opencart version?

Shopping Cart REST API

This extension works & has been tested for versions
  • 1.5.2, 1.5.2.1
  • 1.5.3, 1.5.3.1
  • 1.5.4, 1.5.4.1
  • 1.5.5, 1.5.5.1
  • 1.5.6, 1.5.6.1, 1.5.6.2, 1.5.6.3, 1.5.6.4
  • 2.0.0.0, 2.0.1.0, 2.0.1.1, 2.0.2.0, 2.0.3.1
  • 2.1.0.1, 2.1.0.2
  • 2.2.0.0
  • 2.3.0.0, 2.3.0.1, 2.3.0.2

REST ADMIN API

This extension works & has been tested for versions
  • 1.5.5, 1.5.5.1
  • 1.5.6, 1.5.6.1, 1.5.6.2, 1.5.6.3, 1.5.6.4
  • 2.0.0.0, 2.0.1.0, 2.0.1.1, 2.0.2.0, 2.0.3.1
  • 2.1.0.1, 2.1.0.2
  • 2.2.0.0
  • 2.3.0.0, 2.3.0.1, 2.3.0.2, 2.3.0.3

Does Opencart REST API support languages other than English?

Yes, if you want to change the response language, you have to send extra header in your rest request.

Extra header parameter name is: X-Oc-Merchant-Language

Possible values are: en, de, fr, hu, etc.

Will I receive bugs fixes and updates, and for how long?

Yes, I will send you all bugs fixes and updates for your version for minimum 6 months.

Can I change the source code to fit my needs?

Yes.Please don’t forget, that you may not resell our products. Rights on source code is not for selling.

Do I get the full PHP source?

Yes, you get the full PHP source code.Please don’t forget, that you may not resell our products. Rights on source code is not for selling.

Getting started

What is token TTL?

This is the time to live value of the token, you can set it for example 28 000.

What is my secret key?

You can set any string as secret key.

What is my client ID and client Secret?

Client id, client secret: you can set any string as client id and client secret. Please check GET Token section: http://opencartoauth.opencart-api.com/schema_v2.0_oauth/#!/token/token_get

Do you have any javascript example?

$.ajax({
    url: site+"/api/rest/products",
    type: "GET",
    headers: {
        "X-Oc-Merchant-Id": '123'
        },
        dataType: "json",
        contentType: 'application/json: charset=utf-8',
        async: true,
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function(response) {

            if (response.success) {
                console.log(response.data);
            } else {
                console.log("Error");
            }
        },
        error: function(error) {
            console.log("Error");
        }
});

License

Can I use Opencart REST API on more than one site?

When you buy the extension at usual price you automatically get the one time usage license.

It enables you to use each individual product on a single website only, belonging to either you or your client.

You have to purchase the same package again if you plan to use the same extension in connection with another or other projects.

Contact us if you require it for more and we will quote a volume based price.

Troubleshooting

Error: Client credentials were not found in the headers or body

Paste into your opencart root folder .htaccess file this line:
RewriteRule .* - [E=HTTP_Authorization:%{HTTP:Authorization}]
or
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
or
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

How to add image to product when you add it to cart

You have to POST the file to this URL (the name of the form field have to be “file”)
http://yourdomain.com/index.php?route=tool/upload
If everything was ok, you will get similar response:
{
"code": "841c0e0f9a0a1460d17a7368471d8121b579435b",
"success": "Your file was successfully uploaded!"
}


Then you have to POST the code as an option value when you add the item to the cart
{
"product_id": "42",
"quantity": "2",
"option": {
"218": "5",
"222": "841c0e0f9a0a1460d17a7368471d8121b579435b"
}
}

PHP Fatal error: Uncaught Error: Call to undefined method Cart\\Currency::setRestCurrencyCode()

Please go to Extensions > Modifications and hit the blue “Refresh” button in the upper right corner under the notification icon.

Error: Modification Opencart REST API v2 is using the same ID code as the one you are trying to upload!

You already installed our extension, delete it first from Modification/Modification List

I’m getting the following error: Token problem. Invalid token.

Paste into your opencart root folder .htaccess file this line:
RewriteRule .* - [E=HTTP_Authorization:%{HTTP:Authorization}]
 or
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

I’m getting the following error: Notice: Undefined property: Proxy::setOauthClient in /admin/controller/extension/module/rest_api.php

This error is caused because of OCMOD.

Please go to Extensions > Modifications and hit the blue “Refresh” button in the upper right corner under the notification icon.

No ‘Access-Control-Allow-Origin’ header is present on the requested resource

This is CORS problem. http://enable-cors.org/
       #Add these lines to your .htaccess file
        Header set Access-Control-Allow-Origin "http://localhost"
        Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
        Header set Access-Control-Allow-Headers "X-Oc-Merchant-Language, X-Oc-Store-Id, Content-Type,X-Oc-Merchant-Id, X-Oc-Session"
        Header set Access-Control-Allow-Credentials: true
        RewriteRule .* - [E=HTTP_Authorization:%{HTTP:Authorization}]

GET and POST methods work fine, PUT and DELETE do not work.

Are PUT and DELETE HTTP methods enabled on your server?Add these lines to your .htaccess file:For Apache version < 2.4
<Limit DELETE POST GET PUT>
  Order deny,allow
  Allow from all
</Limit>
For Apache version  >=2.4
<Limit DELETE POST GET PUT>
  Order deny,allow
  Require all granted
</Limit>

I’m getting the following error: {“success”:false,”error”:”Invalid secret key”}

Shopping Cart REST API

You have to send an extra header parameter with the secret key.
The extra header parameter name is “X-Oc-Merchant-Id“.

If you don’t want to use secret key, just leave blank the Secret key field on Rest API configuration page, and extension will work fine.

REST ADMIN API

You have to send an extra header parameter with the secret key.
The extra header parameter name is “X-Oc-Restadmin-Id“.

If you don’t want to use secret key, just leave blank the Secret key field on Rest API configuration page, and extension will work fine.

I’m getting internal server error 500

Please install vqmod : https://code.google.com/p/vqmod/

You need to paste all codes stated in the install.txt file on the root folder index.php , .htaccess file and set a secret key from admin panel and enabled the extension.

If you want to use short URLs like: http://yourdomain.com/api/rest/products, you need to enable RewriteEngine, rename your .htaccess.txt to .htaccess, and paste all RewriteRules from install.txt.

I’m getting always the same response: {success:true}

Don’t cache URLs of rest API. if you’re using NitroCache please add this line to the exclude URL list: api/rest/*

Sample code

PHP sample code for Shopping Cart REST API

Sample PHP code to get products: If your secret key is : 123
$url	= "http://webshop.opencart-api.com:80/api/rest/products";
$secret = "123"; 

$ch = curl_init($url);
		
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	"X-Oc-Merchant-Id: ".$secret
));

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($status != 200) {
echo("ERROR");
}else {
echo($response);
}
Sample PHP code to add product:
$product = array(
	"model"=> "test_model",
	"sku"=> "001",
	"quantity" => "10",
	"price"=> "1000",
	"tax_class_id"=> "9",
	"manufacturer_id"=> "8",
	"sort_order"=> "1",
	"status"=> "1",
	"product_store"=> array(0),
	"product_category"=> array(71),
	"product_description"=>array(
		"1"=>array(
			"name"=>"Api test product",
			"meta_description" => "test product meta_description",
			"meta_keyword" => "test product meta_keyword",
			"description" => "test product description"
			)
		)
	
);
$secret = "123";
$data_string = json_encode($product);                                                                                   
$ch = curl_init('http://webshop.opencart-api.com:80/api/rest/products');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");   
curl_setopt($ch, CURLOPT_HEADER, 0);                                                                  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',     
    'X-Oc-Merchant-Id: '.$secret,                                                                           
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                           
 
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status != 200) {
	echo("ERROR");
}else {
	echo($response);
}

Sample PHP code to upload and set product’s primary image:
$imagePath = '/home/your_folder/Pictures/camera-icon.png';
$imageExtention = preg_replace('/^.*\.([^.]+)$/D', '$1', $imagePath);
$postFields['file'] = "@$imagePath;type=image/$imageExtention";

$secret = "123";                                                                           

$ch = curl_init('http://webshop.opencart-api.com:80/api/rest/products/35/images');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");   
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);                                                                  
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'X-Oc-Merchant-Id: '.$secret                                                                    
));                                                                                                           
 
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status != 200) {
	echo("ERROR");
}else {
	echo($response);
}
Sample PHP code to get OAuth token:
$ch = curl_init('http://opencartoauth.opencart-api.com:80/api/rest/oauth2/token/client_credentials');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: Basic ZGVtb19vYXV0aF9jbGllbnQ6ZGVtb19vYXV0aF9zZWNyZXQ='
    )
);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status != 200) {
    echo("ERROR");
}else {
    echo($response);
}