Cart
Manage Cart

Get Cart Items

get
https://<domain>/<api prefix>/<version>/commerce/cart-items/

Sample Code

Node

var request = require("request");
​
var options = { method: 'GET',
url: 'https://<domain>/<api prefix>/<version>/commerce/cart-items/',
headers:
{ authorization: 'Bearer <access-token>',
apikey: '<apikey>' } };
​
request(options, function (error, response, body) {
if (error) throw new Error(error);
​
console.log(body);
});

PHP

<?php
​
$curl = curl_init();
​
curl_setopt_array($curl, array(
CURLOPT_PORT => "8000",
CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/cart-items/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"apikey: <apikey>",
"authorization: Bearer <access-token>",
),
));
​
$response = curl_exec($curl);
$err = curl_error($curl);
​
curl_close($curl);
​
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

Remove an item from the cart

post
https://<domain>/<api prefix>/<version>/commerce/remove-cart-item/

Sample code

Node

var request = require("request");
​
var options = { method: 'POST',
url: 'https://<domain>/<api prefix>/<version>/commerce/remove-cart-item/',
headers:
{ authorization: 'Bearer <access-token>',
apikey: '<apikey>',
'content-type': 'multipart/form-data' },
formData: { order_id: '9558', pk: '10465' } };
​
request(options, function (error, response, body) {
if (error) throw new Error(error);
​
console.log(body);
});

PHP

<?php
​
$curl = curl_init();
​
curl_setopt_array($curl, array(
CURLOPT_PORT => "8000",
CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/remove-cart-item/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"order_id\"\r\n\r\n9558\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"pk\"\r\n\r\n10465\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"apikey: <apikey>",
"authorization: Bearer <access-token>",
),
));
​
$response = curl_exec($curl);
$err = curl_error($curl);
​
curl_close($curl);
​
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

Error Responses

Status Code
Error Type
Field
Description
400
Validation Error
order_id
This field may not be blank.
400
Validation Error
pk
This field may not be blank.

Update Cart

post
https://
<domain>/<api prefix>/<version>/commerce/update-cart/

Sample Code

Node

var request = require('request');
var options = {
'method': 'GET',
'url': '<domain>/<api prefix>/<version>/commerce/update-cart/',
'headers': {
'apikey': '<apikey>',
'Authorization': 'Bearer <access token>'
},
formData: {
'cart_id': '34',
'line_item_id': '43',
'quantity': '34'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
​

PHP

<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('<domain>/<api prefix>/<version>/commerce/update-cart/');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'apikey' => '<apikey>',
'Authorization' => 'Bearer <access token>'
));
$request->addPostParameter(array(
'cart_id' => '34',
'line_item_id' => '43',
'quantity' => '34'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}