Cart

Manage Cart

Get Cart Items

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

get the list of items in the cart

Headers

HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "cartitems": [
            {
                "id": <id>,
                "order_id_id": <orderid>,
                "vendor_id": <vendor id>,
                "product_id": <produc id>,
                "bundle_id": <bundle id>,
                "line_item_type": <item type>,
                "line_item_label": <item label>,
                "quantity": <quantity>,
                "price": <price>,
                "data": <data>,
                "status": <status>,
                "unit_price": <unit price>,
                "currency_code": <currency_code>,
                "currency_symbol": <currency_symbol>
            }
        ]
    }
}

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/

remove an item from cart by passing item id and order id

Headers

Request Body

HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}

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

Update Cart

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

update cart item quantity

Headers

Request Body

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

Last updated