Sample code for 30+ languages & platforms
Xbase++

Shopify Get all products that belong to a certain collection

See more Shopify Examples

Get all products that belong to a certain collection

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL oSbJson
LOCAL oJson
LOCAL i
LOCAL nCount_i
LOCAL nId
LOCAL cTitle
LOCAL cBody_html
LOCAL cVendor
LOCAL cProduct_type
LOCAL cCreated_at
LOCAL cHandle
LOCAL cUpdated_at
LOCAL cPublished_at
LOCAL nTemplate_suffix
LOCAL cPublished_scope
LOCAL cTags
LOCAL nImageId
LOCAL nImageProduct_id
LOCAL nImagePosition
LOCAL cImageCreated_at
LOCAL cImageUpdated_at
LOCAL nImageWidth
LOCAL nImageHeight
LOCAL cImageSrc
LOCAL j
LOCAL nCount_j
LOCAL nProduct_id
LOCAL cPrice
LOCAL cSku
LOCAL nPosition
LOCAL nGrams
LOCAL cInventory_policy
LOCAL nCompare_at_price
LOCAL cFulfillment_service
LOCAL cInventory_management
LOCAL cOption1
LOCAL nOption2
LOCAL nOption3
LOCAL nTaxable
LOCAL cBarcode
LOCAL nImage_id
LOCAL nInventory_quantity
LOCAL nWeight
LOCAL cWeight_unit
LOCAL nOld_inventory_quantity
LOCAL nRequires_shipping
LOCAL cName
LOCAL k
LOCAL nCount_k
LOCAL cStrVal
LOCAL nWidth
LOCAL nHeight
LOCAL cSrc
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?collection_id=841564295", 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")
    cBody_html := oJson:StringOf("products[i].body_html")
    cVendor := oJson:StringOf("products[i].vendor")
    cProduct_type := oJson:StringOf("products[i].product_type")
    cCreated_at := oJson:StringOf("products[i].created_at")
    cHandle := oJson:StringOf("products[i].handle")
    cUpdated_at := oJson:StringOf("products[i].updated_at")
    cPublished_at := oJson:StringOf("products[i].published_at")
    nTemplate_suffix := oJson:IsNullOf("products[i].template_suffix")
    cPublished_scope := oJson:StringOf("products[i].published_scope")
    cTags := oJson:StringOf("products[i].tags")
    nImageId := oJson:IntOf("products[i].image.id")
    nImageProduct_id := oJson:IntOf("products[i].image.product_id")
    nImagePosition := oJson:IntOf("products[i].image.position")
    cImageCreated_at := oJson:StringOf("products[i].image.created_at")
    cImageUpdated_at := oJson:StringOf("products[i].image.updated_at")
    nImageWidth := oJson:IntOf("products[i].image.width")
    nImageHeight := oJson:IntOf("products[i].image.height")
    cImageSrc := oJson:StringOf("products[i].image.src")
    j := 0
    nCount_j := oJson:SizeOfArray("products[i].variants")
    DO WHILE j < nCount_j
        oJson:J := j
        nId := oJson:IntOf("products[i].variants[j].id")
        nProduct_id := oJson:IntOf("products[i].variants[j].product_id")
        cTitle := oJson:StringOf("products[i].variants[j].title")
        cPrice := oJson:StringOf("products[i].variants[j].price")
        cSku := oJson:StringOf("products[i].variants[j].sku")
        nPosition := oJson:IntOf("products[i].variants[j].position")
        nGrams := oJson:IntOf("products[i].variants[j].grams")
        cInventory_policy := oJson:StringOf("products[i].variants[j].inventory_policy")
        nCompare_at_price := oJson:IsNullOf("products[i].variants[j].compare_at_price")
        cFulfillment_service := oJson:StringOf("products[i].variants[j].fulfillment_service")
        cInventory_management := oJson:StringOf("products[i].variants[j].inventory_management")
        cOption1 := oJson:StringOf("products[i].variants[j].option1")
        nOption2 := oJson:IsNullOf("products[i].variants[j].option2")
        nOption3 := oJson:IsNullOf("products[i].variants[j].option3")
        cCreated_at := oJson:StringOf("products[i].variants[j].created_at")
        cUpdated_at := oJson:StringOf("products[i].variants[j].updated_at")
        nTaxable := oJson:BoolOf("products[i].variants[j].taxable")
        cBarcode := oJson:StringOf("products[i].variants[j].barcode")
        nImage_id := oJson:IntOf("products[i].variants[j].image_id")
        nInventory_quantity := oJson:IntOf("products[i].variants[j].inventory_quantity")
        nWeight := oJson:IntOf("products[i].variants[j].weight")
        cWeight_unit := oJson:StringOf("products[i].variants[j].weight_unit")
        nOld_inventory_quantity := oJson:IntOf("products[i].variants[j].old_inventory_quantity")
        nRequires_shipping := oJson:BoolOf("products[i].variants[j].requires_shipping")
        j := j + 1
    ENDDO
    j := 0
    nCount_j := oJson:SizeOfArray("products[i].options")
    DO WHILE j < nCount_j
        oJson:J := j
        nId := oJson:IntOf("products[i].options[j].id")
        nProduct_id := oJson:IntOf("products[i].options[j].product_id")
        cName := oJson:StringOf("products[i].options[j].name")
        nPosition := oJson:IntOf("products[i].options[j].position")
        k := 0
        nCount_k := oJson:SizeOfArray("products[i].options[j].values")
        DO WHILE k < nCount_k
            oJson:K := k
            cStrVal := oJson:StringOf("products[i].options[j].values[k]")
            k := k + 1
        ENDDO
        j := j + 1
    ENDDO
    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
    j := 0
    nCount_j := oJson:SizeOfArray("products[i].image.variant_ids")
    DO WHILE j < nCount_j
        oJson:J := j
        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",
//        "body_html": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.<\/p>",
//        "vendor": "Apple",
//        "product_type": "Cult Products",
//        "created_at": "2017-09-22T14:08:02-04:00",
//        "handle": "ipod-nano",
//        "updated_at": "2017-09-22T14:08:02-04:00",
//        "published_at": "2007-12-31T19:00:00-05:00",
//        "template_suffix": null,
//        "published_scope": "web",
//        "tags": "Emotive, Flash Memory, MP3, Music",
//        "variants": [
//          {
//            "id": 808950810,
//            "product_id": 632910392,
//            "title": "Pink",
//            "price": "199.00",
//            "sku": "IPOD2008PINK",
//            "position": 1,
//            "grams": 567,
//            "inventory_policy": "continue",
//            "compare_at_price": null,
//            "fulfillment_service": "manual",
//            "inventory_management": "shopify",
//            "option1": "Pink",
//            "option2": null,
//            "option3": null,
//            "created_at": "2017-09-22T14:08:02-04:00",
//            "updated_at": "2017-09-22T14:08:02-04:00",
//            "taxable": true,
//            "barcode": "1234_pink",
//            "image_id": 562641783,
//            "inventory_quantity": 10,
//            "weight": 1.25,
//            "weight_unit": "lb",
//            "old_inventory_quantity": 10,
//            "requires_shipping": true
//          },
//          {
//            "id": 49148385,
//            "product_id": 632910392,
//            "title": "Red",
//            "price": "199.00",
//            "sku": "IPOD2008RED",
//            "position": 2,
//            "grams": 567,
//            "inventory_policy": "continue",
//            "compare_at_price": null,
//            "fulfillment_service": "manual",
//            "inventory_management": "shopify",
//            "option1": "Red",
//            "option2": null,
//            "option3": null,
//            "created_at": "2017-09-22T14:08:02-04:00",
//            "updated_at": "2017-09-22T14:08:02-04:00",
//            "taxable": true,
//            "barcode": "1234_red",
//            "image_id": null,
//            "inventory_quantity": 20,
//            "weight": 1.25,
//            "weight_unit": "lb",
//            "old_inventory_quantity": 20,
//            "requires_shipping": true
//          },
//          {
//            "id": 39072856,
//            "product_id": 632910392,
//            "title": "Green",
//            "price": "199.00",
//            "sku": "IPOD2008GREEN",
//            "position": 3,
//            "grams": 567,
//            "inventory_policy": "continue",
//            "compare_at_price": null,
//            "fulfillment_service": "manual",
//            "inventory_management": "shopify",
//            "option1": "Green",
//            "option2": null,
//            "option3": null,
//            "created_at": "2017-09-22T14:08:02-04:00",
//            "updated_at": "2017-09-22T14:08:02-04:00",
//            "taxable": true,
//            "barcode": "1234_green",
//            "image_id": null,
//            "inventory_quantity": 30,
//            "weight": 1.25,
//            "weight_unit": "lb",
//            "old_inventory_quantity": 30,
//            "requires_shipping": true
//          },
//          {
//            "id": 457924702,
//            "product_id": 632910392,
//            "title": "Black",
//            "price": "199.00",
//            "sku": "IPOD2008BLACK",
//            "position": 4,
//            "grams": 567,
//            "inventory_policy": "continue",
//            "compare_at_price": null,
//            "fulfillment_service": "manual",
//            "inventory_management": "shopify",
//            "option1": "Black",
//            "option2": null,
//            "option3": null,
//            "created_at": "2017-09-22T14:08:02-04:00",
//            "updated_at": "2017-09-22T14:08:02-04:00",
//            "taxable": true,
//            "barcode": "1234_black",
//            "image_id": null,
//            "inventory_quantity": 40,
//            "weight": 1.25,
//            "weight_unit": "lb",
//            "old_inventory_quantity": 40,
//            "requires_shipping": true
//          }
//        ],
//        "options": [
//          {
//            "id": 594680422,
//            "product_id": 632910392,
//            "name": "Color",
//            "position": 1,
//            "values": [
//              "Pink",
//              "Red",
//              "Green",
//              "Black"
//            ]
//          }
//        ],
//        "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
//            ]
//          }
//        ],
//        "image": {
//          "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": [
//          ]
//        }
//      }
//    ]
//  }

? "Example Completed."

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