Sample code for 30+ languages & platforms
Lianja

Shopify Get all products, showing only some attributes

See more Shopify Examples

Get all products, showing only some attributes

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

loRest = createobject("CkRest")

loRest.SetAuthBasic("SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_KEY")

llSuccess = loRest.Connect("chilkat.myshopify.com",443,.T.,.T.)
if (llSuccess <> .T.) then
    ? loRest.LastErrorText
    release loRest
    return
endif

loSbJson = createobject("CkStringBuilder")
llSuccess = loRest.FullRequestNoBodySb("GET","/admin/products.json?fields=id,images,title",loSbJson)
if (llSuccess <> .T.) then
    ? loRest.LastErrorText
    release loRest
    release loSbJson
    return
endif

if (loRest.ResponseStatusCode <> 200) then
    ? "Received error response code: " + str(loRest.ResponseStatusCode)
    ? "Response body:"
    ? loSbJson.GetAsString()
    release loRest
    release loSbJson
    return
endif

loJson = createobject("CkJsonObject")
loJson.LoadSb(loSbJson)

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.

i = 0
lnCount_i = loJson.SizeOfArray("products")
do while i < lnCount_i
    loJson.I = i
    lnId = loJson.IntOf("products[i].id")
    lcTitle = loJson.StringOf("products[i].title")
    j = 0
    lnCount_j = loJson.SizeOfArray("products[i].images")
    do while j < lnCount_j
        loJson.J = j
        lnId = loJson.IntOf("products[i].images[j].id")
        lnProduct_id = loJson.IntOf("products[i].images[j].product_id")
        lnPosition = loJson.IntOf("products[i].images[j].position")
        lcCreated_at = loJson.StringOf("products[i].images[j].created_at")
        lcUpdated_at = loJson.StringOf("products[i].images[j].updated_at")
        lnWidth = loJson.IntOf("products[i].images[j].width")
        lnHeight = loJson.IntOf("products[i].images[j].height")
        lcSrc = loJson.StringOf("products[i].images[j].src")
        k = 0
        lnCount_k = loJson.SizeOfArray("products[i].images[j].variant_ids")
        do while k < lnCount_k
            loJson.K = k
            lnIntVal = loJson.IntOf("products[i].images[j].variant_ids[k]")
            k = k + 1
        enddo
        j = j + 1
    enddo
    i = i + 1
enddo

// A sample JSON response body that is parsed by the above code:

// {
//   "products": [
//     {
//       "id": 632910392,
//       "title": "IPod Nano - 8GB",
//       "images": [
//         {
//           "id": 850703190,
//           "product_id": 632910392,
//           "position": 1,
//           "created_at": "2017-09-22T14:08:02-04:00",
//           "updated_at": "2017-09-22T14:08:02-04:00",
//           "width": 123,
//           "height": 456,
//           "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano.png?v=1506103682",
//           "variant_ids": [
//           ]
//         },
//         {
//           "id": 562641783,
//           "product_id": 632910392,
//           "position": 2,
//           "created_at": "2017-09-22T14:08:02-04:00",
//           "updated_at": "2017-09-22T14:08:02-04:00",
//           "width": 123,
//           "height": 456,
//           "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano-2.png?v=1506103682",
//           "variant_ids": [
//             808950810
//           ]
//         }
//       ]
//     },
//     {
//       "id": 921728736,
//       "title": "IPod Touch 8GB",
//       "images": [
//       ]
//     }
//   ]
// }

? "Example Completed."


release loRest
release loSbJson
release loJson