Sample code for 30+ languages & platforms
Xbase++

Shopify Get all products, showing only some attributes

See more Shopify Examples

Get all products, showing only some attributes

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL oSbJson
LOCAL oJson
LOCAL i
LOCAL nCount_i
LOCAL nId
LOCAL cTitle
LOCAL j
LOCAL nCount_j
LOCAL nProduct_id
LOCAL nPosition
LOCAL cCreated_at
LOCAL cUpdated_at
LOCAL nWidth
LOCAL nHeight
LOCAL cSrc
LOCAL k
LOCAL nCount_k
LOCAL nIntVal

nSuccess := 0

oRest := CreateObject("Chilkat.Rest")

oRest:SetAuthBasic("SHOPIFY_PRIVATE_API_KEY", "SHOPIFY_PRIVATE_API_KEY")

nSuccess := oRest:Connect("chilkat.myshopify.com", 443, 1, 1)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

oSbJson := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestNoBodySb("GET", "/admin/products.json?fields=id,images,title", oSbJson)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    oSbJson:destroy()
    RETURN
ENDIF

IF (oRest:ResponseStatusCode != 200)
    ? "Received error response code: " + Str(oRest:ResponseStatusCode)
    ? "Response body:"
    ? oSbJson:GetAsString()
    oRest:destroy()
    oSbJson:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:LoadSb(oSbJson)

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

i := 0
nCount_i := oJson:SizeOfArray("products")
DO WHILE i < nCount_i
    oJson:I := i
    nId := oJson:IntOf("products[i].id")
    cTitle := oJson:StringOf("products[i].title")
    j := 0
    nCount_j := oJson:SizeOfArray("products[i].images")
    DO WHILE j < nCount_j
        oJson:J := j
        nId := oJson:IntOf("products[i].images[j].id")
        nProduct_id := oJson:IntOf("products[i].images[j].product_id")
        nPosition := oJson:IntOf("products[i].images[j].position")
        cCreated_at := oJson:StringOf("products[i].images[j].created_at")
        cUpdated_at := oJson:StringOf("products[i].images[j].updated_at")
        nWidth := oJson:IntOf("products[i].images[j].width")
        nHeight := oJson:IntOf("products[i].images[j].height")
        cSrc := oJson:StringOf("products[i].images[j].src")
        k := 0
        nCount_k := oJson:SizeOfArray("products[i].images[j].variant_ids")
        DO WHILE k < nCount_k
            oJson:K := k
            nIntVal := oJson: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."

oRest:destroy()
oSbJson:destroy()
oJson:destroy()