Scroll Top

FAQ

General

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.

Yes.

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

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

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

You can use the same license on your dev / test / prod environment.

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.

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.

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
  • 3.x

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
  • 3.x

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

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.

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

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

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 .

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)

Getting started

$.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");
        }
});

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

You can set any string as secret key.

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

Troubleshooting

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

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.

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.

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>
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}]

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.

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]

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

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

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"
}
}

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

You can send the access token in the url as GET parameter.

Use this format:

&access_token={your_access_token}

 

Pay service example:

index.php?route=rest/confirm/confirm&page=pay&access_token={your_access_token}

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 the value of your custom field when you register a new user.

Please add these lines to your php.ini in your opencart root folder

extension=pdo.so
extension=pdo_mysql.so

Sample code

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);
}