Sample code for 30+ languages & platforms
PowerBuilder

Shopify Get all products, showing only some attributes

See more Shopify Examples

Get all products, showing only some attributes

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Rest
oleobject loo_SbJson
oleobject loo_Json
long i
long li_Count_i
long li_Id
string ls_Title
long j
long li_Count_j
long li_Product_id
long li_Position
string ls_Created_at
string ls_Updated_at
long li_Width
long li_Height
string ls_Src
long k
long li_Count_k
long li_IntVal

li_Success = 0

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Rest.SetAuthBasic("SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_KEY")

li_Success = loo_Rest.Connect("chilkat.myshopify.com",443,1,1)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/admin/products.json?fields=id,images,title",loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_SbJson
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Response body:"
    Write-Debug loo_SbJson.GetAsString()
    destroy loo_Rest
    destroy loo_SbJson
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.LoadSb(loo_SbJson)

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

i = 0
li_Count_i = loo_Json.SizeOfArray("products")
do while i < li_Count_i
    loo_Json.I = i
    li_Id = loo_Json.IntOf("products[i].id")
    ls_Title = loo_Json.StringOf("products[i].title")
    j = 0
    li_Count_j = loo_Json.SizeOfArray("products[i].images")
    do while j < li_Count_j
        loo_Json.J = j
        li_Id = loo_Json.IntOf("products[i].images[j].id")
        li_Product_id = loo_Json.IntOf("products[i].images[j].product_id")
        li_Position = loo_Json.IntOf("products[i].images[j].position")
        ls_Created_at = loo_Json.StringOf("products[i].images[j].created_at")
        ls_Updated_at = loo_Json.StringOf("products[i].images[j].updated_at")
        li_Width = loo_Json.IntOf("products[i].images[j].width")
        li_Height = loo_Json.IntOf("products[i].images[j].height")
        ls_Src = loo_Json.StringOf("products[i].images[j].src")
        k = 0
        li_Count_k = loo_Json.SizeOfArray("products[i].images[j].variant_ids")
        do while k < li_Count_k
            loo_Json.K = k
            li_IntVal = loo_Json.IntOf("products[i].images[j].variant_ids[k]")
            k = k + 1
        loop
        j = j + 1
    loop
    i = i + 1
loop

//  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": [
//        ]
//      }
//    ]
//  }

Write-Debug "Example Completed."


destroy loo_Rest
destroy loo_SbJson
destroy loo_Json