Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lnItemId
LOCAL lcName
LOCAL lnPrice
LOCAL lcDescription
LOCAL lnOrderId
LOCAL lcArrivalDate
LOCAL lcOrderDate
LOCAL lnOrderTotal
LOCAL lcAddress
LOCAL i
LOCAL lnCount_i
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://api.simplekart.com/orders/:orderId",loSbResponseBody)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loSbResponseBody
CANCEL
ENDIF
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loHttp.LastHeader
? "Failed."
RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)
* {
* "orderId": 674,
* "items": [
* {
* "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"
* }
* ],
* "arrivalDate": "2020-3-04T13:07:45.962Z",
* "orderDate": "2020-03-06T19:27:26.733Z",
* "orderTotal": 2096,
* "address": "95 Tarkiln Hill St.Laurel, MD 20707"
* }
* Sample code for parsing the JSON response...
* Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
lnOrderId = loJResp.IntOf("orderId")
lcArrivalDate = loJResp.StringOf("arrivalDate")
lcOrderDate = loJResp.StringOf("orderDate")
lnOrderTotal = loJResp.IntOf("orderTotal")
lcAddress = loJResp.StringOf("address")
i = 0
lnCount_i = loJResp.SizeOfArray("items")
DO WHILE i < lnCount_i
loJResp.I = i
lnItemId = loJResp.IntOf("items[i].itemId")
lcName = loJResp.StringOf("items[i].name")
lnPrice = loJResp.IntOf("items[i].price")
lcDescription = loJResp.StringOf("items[i].description")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp
Curl Command
curl -X GET
https://api.simplekart.com/orders/:orderId
Postman Collection Item JSON
{
"name": "Get order details from database",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/orders/:orderId",
"host": [
"{{baseUrl}}"
],
"path": [
"orders",
":orderId"
],
"variable": [
{
"key": "orderId",
"value": "674",
"type": "string",
"description": "(Required) "
}
]
},
"description": "Obtain item details from the database"
},
"response": [
{
"name": "OK - Successfully obtained order details",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/orders/:orderId",
"host": [
"{{baseUrl}}"
],
"path": [
"orders",
":orderId"
],
"variable": [
{
"key": "orderId"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"orderId\": 674,\n \"items\": [\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 \"arrivalDate\": \"2020-3-04T13:07:45.962Z\",\n \"orderDate\": \"2020-03-06T19:27:26.733Z\",\n \"orderTotal\": 2096,\n \"address\": \"95 Tarkiln Hill St.Laurel, MD 20707\"\n}"
},
{
"name": "Bad Request - Invalid order ID supplied",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/orders/:orderId",
"host": [
"{{baseUrl}}"
],
"path": [
"orders",
":orderId"
],
"variable": [
{
"key": "orderId"
}
]
}
},
"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 - Order not found",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/orders/:orderId",
"host": [
"{{baseUrl}}"
],
"path": [
"orders",
":orderId"
],
"variable": [
{
"key": "orderId"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"error\": {\n \"message\": \"The order you are looking for, does not exist\"\n }\n}"
}
]
}