Chilkat Online Tools

DataFlex / SimpleKart E-commerce API / Get items from the database

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJarrResp
    Integer iRespStatusCode
    Variant vJson
    Handle hoJson
    Integer iItemId
    String sName
    Integer iPrice
    String sDescription
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateInt Of hoQueryParams "list" 10 To iSuccess

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.simplekart.com/items" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonArray)) To hoJarrResp
    If (Not(IsComObjectCreated(hoJarrResp))) Begin
        Send CreateComObject of hoJarrResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJarrResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJarrResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJarrResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // 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"
    //   },
    //   {
    //     "itemId": 1658,
    //     "name": "VR Gaming Headset",
    //     "price": 79990,
    //     "description": "VR Gaming Headset puts you at the center of virtual reality's most pulse-pounding, PC-powered gameplay. See the action unfold all around you through our sharpest lenses and next-generation optics. Lose yourself in the experience with a comfortable, improved design that lets you start playing faster and keep playing longer. Insight tracking gives you the power to move throughout your playspace in any direction. No external sensors. No complicated setup. Just hands-on action and interaction with our updated Oculus Touch controllers right out of the box. Step into the game and the future of PC VR."
    //   },
    //   {
    //     "itemId": 1659,
    //     "name": "Classic Loop Top Shaker Bottle, 20-Ounce",
    //     "price": 578,
    //     "description": "Easy to maintain proper nutrition and hydration on-the-go.The wide mouth makes it easy to add scoops of powdered mixes, meal ingredients, and liquids, and embossed markings show both ounces and milliliters for easy measuring anywhere (note that markings on the 20-ounce capacity shaker cup only go up to 12 ounces). Bottle contents and liquids are securely contained thanks to a tightly threaded screw-on lid that creates a leakproof seal, and a flip cap that snaps securely shut for shaking and transportation."
    //   },
    //   {
    //     "itemId": 1660,
    //     "name": "4-Port USB 2.0 Hub",
    //     "price": 505,
    //     "description": "Easily add up to 4 devices with the USB 2.0 Hub. Particularly great for recent notebooks that provide a limited number of USB ports. Achieve full 480 Mbps on each port, or daisy-chain multiple hubs to a maximum of 127 devices.Fully backwards compatible with the USB 1.1 products."
    //   },
    //   {
    //     "itemId": 1661,
    //     "name": "Wipes Flushable Wet Wipes Dispenser, Mint Chill, 48 Count (Pack of 3)",
    //     "price": 938,
    //     "description": "For a superior clean that’s fresh, gentle, and effective, choose Wipes with the CleaningRipples Texture. Wipes are 100 percent flushable, remove odor causing bacteria and offer a large, dual layer wipe to clean better than when using dry toilet paper alone."
    //   },
    //   {
    //     "itemId": 1662,
    //     "name": "Cordless Vacuum Cleaner",
    //     "price": 41893,
    //     "description": "Twice the suction of any cord-free vacuum. Cord-free cleaning, made easier. Intelligently optimizes suction and run time, to deep clean everywhere. With fade-free battery power and a battery-saving trigger. And real-time reporting on the LCD screen to give you control of your clean. The Dynamic Load Sensor (DLS) system automatically changes the motor speed between carpets and hard floors. For deep cleaning across floor types."
    //   },
    //   {
    //     "itemId": 1663,
    //     "name": "Hair Dryer",
    //     "price": 1400,
    //     "description": "Hair dryer is engineered to protect hair from extreme heat damage, with the fastest drying+ and controlled styling to help increase smoothness by 75%, increase shine by up to 132% and decrease frizz and flyaways by up to 61%."
    //   },
    //   {
    //     "itemId": 1664,
    //     "name": "Business Z27n G2 27 inch LED LCD Monitor",
    //     "price": 24485,
    //     "description": "Be a productive powerhouse with the sleek QHD HP Z27n G2 27-inch Display. This virtually seamless display is factory-tested for reliability and longevity with integrated color calibration, uninterrupted multi-screen tiling, and expansive device connections, including USB-C™. Multi-screen productivity with no disruptions Streamline multi-tasking on multiple displays with a 3-sided micro-edge bezel, and daisy chain up to 2 displays per workstation with DisplayPort™."
    //   },
    //   {
    //     "itemId": 1665,
    //     "name": "Smart Watch",
    //     "price": 1805,
    //     "description": "Built-in Multi-Sports Mode, record your Running, Cycling, Football, Swimming, Table Tennis, Badminton, Climbing, recording your daily sports data."
    //   },
    //   {
    //     "itemId": 1666,
    //     "name": "Learning Thermostat, 3rd Gen, Smart Thermostat",
    //     "price": 15746,
    //     "description": "Learning Thermostat is a smart thermostat that learns what temperatures you like, turns itself down when you’re away and connects to your phone. It has a big, sharp display. And it’s proven to help save energy. In independent studies, the Thermostat saved an average of 10% to 12% on heating bills and 15% on cooling bills."
    //   },
    //   {
    //     "itemId": 16247,
    //     "name": "Postman Merch",
    //     "price": 15,
    //     "description": "Official T-shirt for the Postman community."
    //   }
    // ]

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

    Move 0 To i
    Get ComSize Of hoJarrResp To iCount_i
    While (i < iCount_i)
        Get ComObjectAt Of hoJarrResp i To vJson
        If (IsComObject(vJson)) Begin
            Get Create (RefClass(cComChilkatJsonObject)) To hoJson
            Set pvComObject Of hoJson To vJson
        End
        Get ComIntOf Of hoJson "itemId" To iItemId
        Get ComStringOf Of hoJson "name" To sName
        Get ComIntOf Of hoJson "price" To iPrice
        Get ComStringOf Of hoJson "description" To sDescription
        Send Destroy of hoJson
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -G -d "list=10"
https://api.simplekart.com/items

Postman Collection Item JSON

{
  "name": "Get items from the database",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/items?list=10",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "items"
      ],
      "query": [
        {
          "key": "list",
          "value": "10",
          "description": "Number of items to be displayed"
        }
      ]
    },
    "description": "Pull a list of items from item database"
  },
  "response": [
    {
      "name": "OK - Successful pull of items",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/items?list=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "items"
          ],
          "query": [
            {
              "key": "list",
              "value": "10"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n {\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 },\n {\n  \"itemId\": 1658,\n  \"name\": \"VR Gaming Headset\",\n  \"price\": 79990,\n  \"description\": \"VR Gaming Headset puts you at the center of virtual reality's most pulse-pounding, PC-powered gameplay. See the action unfold all around you through our sharpest lenses and next-generation optics. Lose yourself in the experience with a comfortable, improved design that lets you start playing faster and keep playing longer. Insight tracking gives you the power to move throughout your playspace in any direction. No external sensors. No complicated setup. Just hands-on action and interaction with our updated Oculus Touch controllers right out of the box. Step into the game and the future of PC VR.\"\n },\n {\n  \"itemId\": 1659,\n  \"name\": \"Classic Loop Top Shaker Bottle, 20-Ounce\",\n  \"price\": 578,\n  \"description\": \"Easy to maintain proper nutrition and hydration on-the-go.The wide mouth makes it easy to add scoops of powdered mixes, meal ingredients, and liquids, and embossed markings show both ounces and milliliters for easy measuring anywhere (note that markings on the 20-ounce capacity shaker cup only go up to 12 ounces). Bottle contents and liquids are securely contained thanks to a tightly threaded screw-on lid that creates a leakproof seal, and a flip cap that snaps securely shut for shaking and transportation.\"\n },\n {\n  \"itemId\": 1660,\n  \"name\": \"4-Port USB 2.0 Hub\",\n  \"price\": 505,\n  \"description\": \"Easily add up to 4 devices with the USB 2.0 Hub. Particularly great for recent notebooks that provide a limited number of USB ports. Achieve full 480 Mbps on each port, or daisy-chain multiple hubs to a maximum of 127 devices.Fully backwards compatible with the USB 1.1 products.\"\n },\n {\n  \"itemId\": 1661,\n  \"name\": \"Wipes Flushable Wet Wipes Dispenser, Mint Chill, 48 Count (Pack of 3)\",\n  \"price\": 938,\n  \"description\": \"For a superior clean that’s fresh, gentle, and effective, choose Wipes with the CleaningRipples Texture. Wipes are 100 percent flushable, remove odor causing bacteria and offer a large, dual layer wipe to clean better than when using dry toilet paper alone.\"\n },\n {\n  \"itemId\": 1662,\n  \"name\": \"Cordless Vacuum Cleaner\",\n  \"price\": 41893,\n  \"description\": \"Twice the suction of any cord-free vacuum. Cord-free cleaning, made easier. Intelligently optimizes suction and run time, to deep clean everywhere. With fade-free battery power and a battery-saving trigger. And real-time reporting on the LCD screen to give you control of your clean. The Dynamic Load Sensor (DLS) system automatically changes the motor speed between carpets and hard floors. For deep cleaning across floor types.\"\n },\n {\n  \"itemId\": 1663,\n  \"name\": \"Hair Dryer\",\n  \"price\": 1400,\n  \"description\": \"Hair dryer is engineered to protect hair from extreme heat damage, with the fastest drying+ and controlled styling to help increase smoothness by 75%, increase shine by up to 132% and decrease frizz and flyaways by up to 61%.\"\n },\n {\n  \"itemId\": 1664,\n  \"name\": \"Business Z27n G2 27 inch LED LCD Monitor\",\n  \"price\": 24485,\n  \"description\": \"Be a productive powerhouse with the sleek QHD HP Z27n G2 27-inch Display. This virtually seamless display is factory-tested for reliability and longevity with integrated color calibration, uninterrupted multi-screen tiling, and expansive device connections, including USB-C™. Multi-screen productivity with no disruptions Streamline multi-tasking on multiple displays with a 3-sided micro-edge bezel, and daisy chain up to 2 displays per workstation with DisplayPort™.\"\n },\n {\n  \"itemId\": 1665,\n  \"name\": \"Smart Watch\",\n  \"price\": 1805,\n  \"description\": \"Built-in Multi-Sports Mode, record your Running, Cycling, Football, Swimming, Table Tennis, Badminton, Climbing, recording your daily sports data.\"\n },\n {\n  \"itemId\": 1666,\n  \"name\": \"Learning Thermostat, 3rd Gen, Smart Thermostat\",\n  \"price\": 15746,\n  \"description\": \"Learning Thermostat is a smart thermostat that learns what temperatures you like, turns itself down when you’re away and connects to your phone. It has a big, sharp display. And it’s proven to help save energy. In independent studies, the Thermostat saved an average of 10% to 12% on heating bills and 15% on cooling bills.\"\n },\n {\n  \"itemId\": 16247,\n  \"name\": \"Postman Merch\",\n  \"price\": 15,\n  \"description\": \"Official T-shirt for the Postman community.\"\n }\n]"
    }
  ]
}