How to start your integration with API2Cart
API2Cart provides a single API to integrate with many shopping platforms, including industry leaders like Shopify, Magento, WooCommerce, Bigcommerce, Volusion, PrestaShop, OpenCart, and others.
The API is accessed over HTTPS protocol and is available for authenticated users only. It is based on the RESTful principles, which makes it easier to test and implement.
1. How to start your work with API2Cart
Firstly, you need to register an account. In your account you will find your unique API key. It is a code generated by API2Cart for each user individually. It provides you with access rights on the API. You will use your API key to establish a connection between the service and stores you are going to work with. Personal API Key helps us to identify users who perform API requests and allows to track and control API usage.
To be able to communicate with store data you need to add that store to your API2Cart account.
The process of connecting a store depends on a type of eCommerce platform:
- based on a hosted platform
- based on an open-source platform
You can add your store manually to the list by clicking the “Add store” button in your API2Cart account. Paste your store’s URL, select the store’s type, and enter the needed information that depends on the chosen store type. You will have to provide API Key/Token and password if it is a hosted platform or use bridge files to establish a connection to other carts. See the full list of requirements for different platforms here.
Also, you can add the store automatically via API request using account.cart.add method with the same credentials described above.
You can send a request via Postman or visit our Interactive Docs.
Here is a short video guide on how to do it in a few clicks
Stores based on Shopify or Bigommerce may be added via OAuth. Find more details here.
To connect stores that are based on open-source shopping platforms like Magento, WooCommerce, PrestaShop, and CS-Cart and others we use the Connection Bridge file.
There are two ways you can install Bridge file on the store:
You can download plugins for needed platforms in the “Build Plugin” section on your API2Cart account.
Please find our guides on how to get needed credentials on different platforms here.
Note: API2Cart works on the back-end of your system. It means that your customers do not need to interact with API2Cart. To establish the connection with their stores you can provide a UI in your application where your customer can download the plugin and provide needed credentials.
2. Getting Started with API
Before starting work with API explore our documentation.
For testing purposes, you can execute needed methods via our Interactive Docs, from your account or via Postman.
Also, you can download and use our SDK and check out some recommendations for developers.
To make it easier for you to navigate your integration logic based on our API, we outlined general patterns that work for software of particular industries. Click here to read the details.
Also, you can find some patterns to work with different entities:
-
Products
The Product API methods allow you to manage products in the store. In particular, you can do the following:
- Create - add products
- Read - find and retrieve lists and specific info
- Update - update item data
- Delete - delete products
Call the product.add method to add new products to the store. Do not forget to specify the necessary parameters.
public function apiAdd($params) { $params = array( 'name' => 'Bag', 'model' => 'bag_01', 'description' => 'This is new product', 'price' => 99.9, 'quantity' => 12, 'manufacturer'=> 'Test', ); return $api->request('product.add', $params); }
Note: You can add image, tax, manufacturer, option, variant, or other info to the product by calling the following methods:
- product.image.add
- product.manufacturer.add
- product.option.add
-
product.option.assign
- product.option.value.add
- product.option.value.assign
-
product.tax.add
- product.variant.add
To see the whole list of supported API methods, jump into documentation.
To update a product, call the product.list method and retrieve the product id.
public function apiList($params) { $params = array( 'start' => 0, 'count' => 50, 'params' => 'id,name,price', ); return $api->request('product.list', $params); }
Use the product id to update the price and inventory(quantity) for this product by executing the product.update method.
public function apiUpdate($params) { $params = array( 'id' => 69, 'price' => 89, ); return $api->request('product.update', $params); }
Tip: To update variant, image, and product option values, call the following methods:
-
product.variant.update
-
product.image.update
-
product.option.value.update
For more API methods visit our documentation.
-
Products in API v1.1
First, we recommend you to explore the Product Methods documentation. Most methods support filters like modified_from, modified_to.
When working with shopping platforms that support multilanguage or/and multistore, you need to pass store_id and/or lang_id parameters. In case the parameter is not passed, we automatically set the default value of store_id and lang_id.
API2Cart returns response only for one language and one store in one request. To get the data for other stores or in other languages, send a request specifying other store_id and lang_id. Use cart.info method to retrieve the list of stores and languages if they are multiple.
Use product.count method to get the amount of products.
Use product.list or product.info to get information on products. The response structure can be found in the end of description of each method.
There can be the following types of products in product.list or product.info response: simple, virtual, configurable, bundle, grouped, downloadable, gift_card. For WooCommerce there are also supported simple-subscription і configurable-subscription product types.
- simple - a simple product that can be a standalone product or as a part of configurable, bundle or grouped product.
- virtual - a non-physical product like service, warranty, subscription. It can be a standalone product or a part of configurable or grouped types.
- configurable - a product that contains variants based on option combinations.
- bundle - a product that consists of separate products both physical and virtual. The customer can select which products and how many of them will form the final bundle product. This product type is often used in in electronics, e.g. cameras or computers.
- grouped - several separate products gathered into a group. You can find the ids of products included in a group in the grouped_products_ids massive in response of product.list or product.info. To get the info about these products, use product.list method specifying products_ids parameter. The parameter value must be unique ids that are in grouped_products_ids.
- downloadable - an electronic product that can be downloaded: multimedia or software.
- gift_card - a gift certificate of a certain value.
- simple-subscription and configurable-subscription are similar to virtual products. These types are used only in WooCommerce stores when WooCommerce Subscriptions module is active. Configurable-subscription type has variants.
To get variants or bundle items use product.child_item.list, specifying product_id or product_ids parameter to get list of child items of a certain product or few. If you specify “product_id=1”, the method will return child items for product with id=1, using product_ids parameter you can get list of child items for multiple products (max 100).
product.child_item.list does not have a separate method for getting total number of child items. However, there is a total_count field in response that returns the total number of child items for a specific request with the specified parameters. For example, if you make two requests for the same product_ids, but in one request you specify avail_sale parameter, their total_count values can be different. There can be requests with zero count, in that case you can find out only the number of variants, for example “product.child_item.list.json?product_ids=a,b,c&count=0”.
product.child_item.list method has a combination field in response, which contains option ids and their values that form a particular variant or bundle item. But not always all the options contained in the product form a combination of variants. Some platforms (like Magento or WooCommerce) allow custom options, that don’t form combination but allow to additionally customize the product, even if it has variants.
Use “params=force_all” parameter only when you really need all the available information. Otherwise, it is better to specify the needed fields, for example “params=id, name, price, advanced_price, quantity”.
-
Retrieve the needed products using product.list or product.info methods
-
Get product ids if the type of product is configurable, bundle or configurable-subscription
-
Get all ids from grouped_products_ids if the product type is grouped
-
Get all ids from grouped_products_ids if the product type is grouped. Retrieve variants and bundle components using product.child_item.list method specifying product_ids parameter. (See how to get product ids in step 3)
-
Retrieve all products contained in groups using product.list method specifying product_ids parameter. (See how to get product ids in step 3)
Data retrieval order:
An example of data retrieval for products and their child items (variant, bundle items).
-
Call product.list or product.info method and collect received ids for products of configurable or bundle types.
Request example: product.list.json?api_key=xxxxx&store_key=xxxxx&start=0&count=5¶ms=id,name,price,type,product_optionsResponse example:
{ "return_code": 0, "return_message": "", "result": { "product": [ { "id": "93", "type": "configurable", "name": "[Sample] 1 L Le Parfait Jar", "price": 9.95, "product_options": [ { "id": "32", "product_option_id": 112, "name": "Size", "description": "Size", "sort_order": 1, "type": "radio", "required": true, "option_items": [ { "id": "95", "product_option_item_id": null, "name": "Small", "sort_order": 0, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "Small" } }, { "id": "96", "product_option_item_id": null, "name": "Medium", "sort_order": 1, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "Medium" } }, { "id": "97", "product_option_item_id": null, "name": "Large", "sort_order": 2, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "Large" } } ], "additional_fields": { "default_option_id": null } }, { "id": "3", "product_option_id": 111, "name": "Color", "description": "Color", "sort_order": 0, "type": "radio", "required": true, "option_items": [ { "id": "7", "product_option_item_id": null, "name": "Silver", "sort_order": 1, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#cccccc" } }, { "id": "8", "product_option_item_id": null, "name": "Black", "sort_order": 2, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#000000" } }, { "id": "10", "product_option_item_id": null, "name": "Blue", "sort_order": 4, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#123c91" } }, { "id": "13", "product_option_item_id": null, "name": "Orange", "sort_order": 7, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#e35e20" } } ], "additional_fields": { "default_option_id": null } } ] }, { "id": "107", "type": "configurable", "name": "[Sample] Dustpan & Brush", "price": 34.95, "product_options": [ { "id": "3", "product_option_id": 114, "name": "Color", "description": "Color", "sort_order": 0, "type": "radio", "required": true, "option_items": [ { "id": "7", "product_option_item_id": null, "name": "Silver", "sort_order": 1, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#cccccc" } }, { "id": "8", "product_option_item_id": null, "name": "Black", "sort_order": 2, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#000000" } }, { "id": "10", "product_option_item_id": null, "name": "Blue", "sort_order": 4, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#123c91" } }, { "id": "13", "product_option_item_id": null, "name": "Orange", "sort_order": 7, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "#e35e20" } } ], "additional_fields": { "default_option_id": null } } ] }, { "id": "111", "type": "simple", "name": "[Sample] Smith Journal 13", "price": 25, "product_options": [ { "id": "31", "product_option_id": 113, "name": "EULA", "description": "EULA", "sort_order": 0, "type": "checkbox", "required": true, "option_items": [ { "id": "93", "product_option_item_id": null, "name": "Yes", "sort_order": 0, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "Yes" } }, { "id": "94", "product_option_item_id": null, "name": "No", "sort_order": 1, "price": 0, "weight": 0, "quantity": null, "type_price": "percent", "sku": null, "additional_fields": { "full_description": "No" } } ], "additional_fields": { "default_option_id": "94" } } ] } ] } }
-
Call product.child_item.list specifying “product_ids” parameter
Request example: product.child_item.list.json?api_key=xxxxx&store_key=xxxxxx&start=5&count=10¶ms=id,default_price,advanced_price,combination,sku,parent_id&product_ids=93,107Response example:
{ "return_code": 0, "return_message": "", "result": { "total_count": 16, "children": [ { "id": "56", "parent_id": "93", "sku": "SLLPJ-973630F5", "combination": [ { "option_id": "111", "option_value_id": "10" }, { "option_id": "112", "option_value_id": "97" } ], "default_price": 7, "advanced_price": [ { "id": "sp", "value": 7, "avail": true, "group_id": null, "quantity_from": null, "start_time": null, "expire_time": null } ] }, { "id": "57", "parent_id": "93", "sku": "SLLPJ-889E9C0A", "combination": [ { "option_id": "111", "option_value_id": "13" }, { "option_id": "112", "option_value_id": "97" } ], "default_price": 7, "advanced_price": [ { "id": "sp", "value": 7, "avail": true, "group_id": null, "quantity_from": null, "start_time": null, "expire_time": null } ] }, { "id": "77", "parent_id": "107", "sku": "SIL-EDF0AC9C", "combination": [ { "option_id": "114", "option_value_id": "7" } ], "default_price": 34.95, "advanced_price": [ ] }, { "id": "78", "parent_id": "107", "sku": "BLA-6D013D80", "combination": [ { "option_id": "114", "option_value_id": "8" } ], "default_price": 34.95, "advanced_price": [ ] }, { "id": "79", "parent_id": "107", "sku": "BLU-2D71C660", "combination": [ { "option_id": "114", "option_value_id": "10" } ], "default_price": 34.95, "advanced_price": [ ] }, { "id": "80", "parent_id": "107", "sku": "ORA-446C93BB", "combination": [ { "option_id": "114", "option_value_id": "13" } ], "default_price": 34.95, "advanced_price": [ ] } ] } }
-
Orders
The Order API methods allow you to manage orders in the store. In particular, you can do the following:
- Create - add orders
- Read - find and retrieve lists and specific info
- Update - update order data
Call the order.add method to add orders to the store. Do not forget to specify the necessary parameters.
public function apiAdd($params) { $params = array( 'customer_email' => '[email protected]', 'order_status' => 'Complete', 'bill_first_name' => 'Adam', 'bill_last_name' => 'Smith', 'bill_address_1' => 'Green str. 35', 'bill_city' => 'Chicago', 'bill_postcode' => '12345', 'bill_state' => 'IL', 'bill_country' => 'US', 'total_price' => '23.56', 'order_item_id_1' => 8, 'order_item_name_1' => 'Bag', 'order_item_model_1' => 'bag_01', 'order_item_price_1' => 89, 'order_item_quantity_1' => 3, ); return = $api->request('order.add', $params); }
If you want to update an order, call the order.list method and get the order id.
public function apiList($params) { $params = array( 'start' => 0, 'count' => 5, 'params' => 'id,customer,status' ); return $api->request('order.list', $params); }
Use the order id to update the comment and order status by calling the order.update method.
public function apiUpdate($params) { $params = array( 'order_id' => 11, 'order_status' => 'Pending', 'comment' => 'Order comment' ); return $api->request('order.update', $params);//returns the number of updated orders }
Tip: To count orders in the store, execute the order.count method.
For more API methods explore our documentation.
-
Customers
The Customer API methods allow you to manage customers in the store. In particular, you can do the following:
- Create - add customers
- Read - find and retrieve lists and specific info
- Update - update customer details
- Delete - delete customers
Call the customer.add method to add customers to the store. Do not forget to specify the necessary parameters.
public function apiAdd($params) { $params = array( 'email' => '[email protected]', 'first_name' => 'John', 'last_name' => 'Smith', ); return $api->request('customer.add', $params); }
To update a customer, call the customer.list method and retrieve the customer id.
public function apiList($params) { $params = array( 'start' => 0, 'count' => 5 ); return $api->request('customer.list', $params); }
Use the customer id to call the customer.update method.
public function apiUpdate($params) { $params = array( 'id' => 11, 'first_name' => 'Jack', 'last_name' => 'Smith', ); return $api->request('customer.update', $params); }
For more API methods explore our documentation.
-
Categories
The Category API methods allow you to manage categories in the store. In particular, you can do the following:
- Create - add categories
- Read - find and retrieve lists and specific info
- Update - update category data
- Delete - delete categories
Use the category.add method to add categories to the store. Do not forget to specify the necessary parameters.
public function apiAdd($params) { $params = array( 'name' => 'Shoes' ); return $api->request('category.add', $params); }
To update a category, call the category.list method and get the category id.
public function apiList($params) { $params = array( 'start' => 2, 'count' => 2, ); return $api->request('category.list', $params); }
Use the category id to execute the category.update method.
public function apiUpdate($params) { $params = array( 'id' => 20, 'avail' => 'false', 'meta_title' => 'meta title for category' ); return $api->request('category.update', $params); }
To assign a product to a category, call the product.list and category.list methods and get product id and category id.
Then use the ids to call the category.assign method.
public function apiAssign($params) { $params = array( 'product_id' => 69, 'category_id' => 20, ); return $api->request('category.assign', $params); }
For more API methods jump into our documentation.
Webhooks
API2Cart webhook is a mechanism for getting notifications when some changes or events on shopping carts occur. For example, the order.update webhook triggers every time when the order status changes. In this case, the JSON formatted data is being sent to the specified URL.
You can check which events you can work with via webhooks here.
For additional information, you can visit our FAQ and Troubleshooting sections. If you experience any other issues feel free to contact us via live chat.