Chilkat Online Tools

Node.js / SimpleKart E-commerce API / Get item details from the database

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    var sbResponseBody = new chilkat.StringBuilder();
    success = http.QuickGetSb("https://api.simplekart.com/items/:itemId",sbResponseBody);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    var jResp = new chilkat.JsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.EmitCompact = false;

    console.log("Response Body:");
    console.log(jResp.Emit());

    var respStatusCode = http.LastStatus;
    console.log("Response Status Code = " + respStatusCode);
    if (respStatusCode >= 400) {
        console.log("Response Header:");
        console.log(http.LastHeader);
        console.log("Failed.");
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "itemId": 1657,
    //   "name": "Smart WiFi Router",
    //   "price": 2096,
    //   "description": "Wifi router/wireless router. One of routers for wireless internet, wireless routers for home. Dual band router and gigabit router. Ideal as internet router also gaming router. Long range coverage with high speed. Compatible with all 802.11ac devices and below. 5ghz router/5g router Frequency Range: 2.4GHz and 5GHz; Interface Available: 4 x 10/100/1000Mbps LAN Ports, 1 10/100/1000Mbps WAN Port, 1 USB 2.0 Ports; Protocols Supported: Supports IPv4 and IPv6; System Requirement: Microsoft Windows 98SE NT 2000 XP Vista, or Windows 7 Windows 8/8.1/10, MAC OS NetWare UNIX or Linux; Wireless Standards: IEEE 802.11ac/n/a 5GHz, IEEE 802.11b/g/n 2.4GH"
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    var itemId = jResp.IntOf("itemId");
    var name = jResp.StringOf("name");
    var price = jResp.IntOf("price");
    var description = jResp.StringOf("description");

}

chilkatExample();

Curl Command

curl -X GET
https://api.simplekart.com/items/:itemId

Postman Collection Item JSON

{
  "name": "Get item details from the database ",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/items/:itemId",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "items",
        ":itemId"
      ],
      "variable": [
        {
          "key": "itemId",
          "value": "1657",
          "type": "string",
          "description": "(Required) Id of the item to pull details of"
        }
      ]
    },
    "description": "Obtain item details from item database"
  },
  "response": [
    {
      "name": "OK - Successfully obtained order details",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/items/:itemId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "items",
            ":itemId"
          ],
          "variable": [
            {
              "key": "itemId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"itemId\": 1657,\n \"name\": \"Smart WiFi Router\",\n \"price\": 2096,\n \"description\": \"Wifi router/wireless router. One of routers for wireless internet, wireless routers for home. Dual band router and gigabit router. Ideal as internet router also gaming router. Long range coverage with high speed. Compatible with all 802.11ac devices and below. 5ghz router/5g router Frequency Range: 2.4GHz and 5GHz; Interface Available: 4 x 10/100/1000Mbps LAN Ports, 1 10/100/1000Mbps WAN Port, 1 USB 2.0 Ports; Protocols Supported: Supports IPv4 and IPv6; System Requirement: Microsoft Windows 98SE NT 2000 XP Vista, or Windows 7 Windows 8/8.1/10, MAC OS NetWare UNIX or Linux; Wireless Standards: IEEE 802.11ac/n/a 5GHz, IEEE 802.11b/g/n 2.4GH\"\n}"
    },
    {
      "name": "Bad Request - Invalid item ID supplied",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/items/:itemId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "items",
            ":itemId"
          ],
          "variable": [
            {
              "key": "itemId"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"error\": {\n  \"message\": \"Provided Id is invalid\"\n }\n}"
    },
    {
      "name": "Not Found - Item not found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/items/:itemId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "items",
            ":itemId"
          ],
          "variable": [
            {
              "key": "itemId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"error\": {\n  \"message\": \"The item you are looking for, does not exist\"\n }\n}"
    }
  ]
}