Cart
Manage Cart

Get Cart Items

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

Sample Code

Node

1
var request = require("request");
2
​
3
var options = { method: 'GET',
4
url: 'https://<domain>/<api prefix>/<version>/commerce/cart-items/',
5
headers:
6
{ authorization: 'Bearer <access-token>',
7
apikey: '<apikey>' } };
8
​
9
request(options, function (error, response, body) {
10
if (error) throw new Error(error);
11
​
12
console.log(body);
13
});
Copied!

PHP

1
<?php
2
​
3
$curl = curl_init();
4
​
5
curl_setopt_array($curl, array(
6
CURLOPT_PORT => "8000",
7
CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/cart-items/",
8
CURLOPT_RETURNTRANSFER => true,
9
CURLOPT_ENCODING => "",
10
CURLOPT_MAXREDIRS => 10,
11
CURLOPT_TIMEOUT => 30,
12
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13
CURLOPT_CUSTOMREQUEST => "GET",
14
CURLOPT_HTTPHEADER => array(
15
"apikey: <apikey>",
16
"authorization: Bearer <access-token>",
17
),
18
));
19
​
20
$response = curl_exec($curl);
21
$err = curl_error($curl);
22
​
23
curl_close($curl);
24
​
25
if ($err) {
26
echo "cURL Error #:" . $err;
27
} else {
28
echo $response;
29
}
Copied!

Remove an item from the cart

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

Sample code

Node

1
var request = require("request");
2
​
3
var options = { method: 'POST',
4
url: 'https://<domain>/<api prefix>/<version>/commerce/remove-cart-item/',
5
headers:
6
{ authorization: 'Bearer <access-token>',
7
apikey: '<apikey>',
8
'content-type': 'multipart/form-data' },
9
formData: { order_id: '9558', pk: '10465' } };
10
​
11
request(options, function (error, response, body) {
12
if (error) throw new Error(error);
13
​
14
console.log(body);
15
});
Copied!

PHP

1
<?php
2
​
3
$curl = curl_init();
4
​
5
curl_setopt_array($curl, array(
6
CURLOPT_PORT => "8000",
7
CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/remove-cart-item/",
8
CURLOPT_RETURNTRANSFER => true,
9
CURLOPT_ENCODING => "",
10
CURLOPT_MAXREDIRS => 10,
11
CURLOPT_TIMEOUT => 30,
12
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13
CURLOPT_CUSTOMREQUEST => "POST",
14
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--",
15
CURLOPT_HTTPHEADER => array(
16
"apikey: <apikey>",
17
"authorization: Bearer <access-token>",
18
),
19
));
20
​
21
$response = curl_exec($curl);
22
$err = curl_error($curl);
23
​
24
curl_close($curl);
25
​
26
if ($err) {
27
echo "cURL Error #:" . $err;
28
} else {
29
echo $response;
30
}
Copied!

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

1
var request = require('request');
2
var options = {
3
'method': 'GET',
4
'url': '<domain>/<api prefix>/<version>/commerce/update-cart/',
5
'headers': {
6
'apikey': '<apikey>',
7
'Authorization': 'Bearer <access token>'
8
},
9
formData: {
10
'cart_id': '34',
11
'line_item_id': '43',
12
'quantity': '34'
13
}
14
};
15
request(options, function (error, response) {
16
if (error) throw new Error(error);
17
console.log(response.body);
18
});
19
​
Copied!

PHP

1
<?php
2
require_once 'HTTP/Request2.php';
3
$request = new HTTP_Request2();
4
$request->setUrl('<domain>/<api prefix>/<version>/commerce/update-cart/');
5
$request->setMethod(HTTP_Request2::METHOD_GET);
6
$request->setConfig(array(
7
'follow_redirects' => TRUE
8
));
9
$request->setHeader(array(
10
'apikey' => '<apikey>',
11
'Authorization' => 'Bearer <access token>'
12
));
13
$request->addPostParameter(array(
14
'cart_id' => '34',
15
'line_item_id' => '43',
16
'quantity' => '34'
17
));
18
try {
19
$response = $request->send();
20
if ($response->getStatus() == 200) {
21
echo $response->getBody();
22
}
23
else {
24
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
25
$response->getReasonPhrase();
26
}
27
}
28
catch(HTTP_Request2_Exception $e) {
29
echo 'Error: ' . $e->getMessage();
30
}
Copied!
Last modified 2mo ago