PowerBuilder
PowerBuilder
Shopify Get all products that belong to a certain collection
See more Shopify Examples
Get all products that belong to a certain collectionChilkat PowerBuilder Downloads
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
string ls_Body_html
string ls_Vendor
string ls_Product_type
string ls_Created_at
string ls_Handle
string ls_Updated_at
string ls_Published_at
long li_Template_suffix
string ls_Published_scope
string ls_Tags
long li_ImageId
long li_ImageProduct_id
long li_ImagePosition
string ls_ImageCreated_at
string ls_ImageUpdated_at
long li_ImageWidth
long li_ImageHeight
string ls_ImageSrc
long j
long li_Count_j
long li_Product_id
string ls_Price
string ls_Sku
long li_Position
long li_Grams
string ls_Inventory_policy
long li_Compare_at_price
string ls_Fulfillment_service
string ls_Inventory_management
string ls_Option1
long li_Option2
long li_Option3
long li_Taxable
string ls_Barcode
long li_Image_id
long li_Inventory_quantity
long li_Weight
string ls_Weight_unit
long li_Old_inventory_quantity
long li_Requires_shipping
string ls_Name
long k
long li_Count_k
string ls_StrVal
long li_Width
long li_Height
string ls_Src
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?collection_id=841564295",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")
ls_Body_html = loo_Json.StringOf("products[i].body_html")
ls_Vendor = loo_Json.StringOf("products[i].vendor")
ls_Product_type = loo_Json.StringOf("products[i].product_type")
ls_Created_at = loo_Json.StringOf("products[i].created_at")
ls_Handle = loo_Json.StringOf("products[i].handle")
ls_Updated_at = loo_Json.StringOf("products[i].updated_at")
ls_Published_at = loo_Json.StringOf("products[i].published_at")
li_Template_suffix = loo_Json.IsNullOf("products[i].template_suffix")
ls_Published_scope = loo_Json.StringOf("products[i].published_scope")
ls_Tags = loo_Json.StringOf("products[i].tags")
li_ImageId = loo_Json.IntOf("products[i].image.id")
li_ImageProduct_id = loo_Json.IntOf("products[i].image.product_id")
li_ImagePosition = loo_Json.IntOf("products[i].image.position")
ls_ImageCreated_at = loo_Json.StringOf("products[i].image.created_at")
ls_ImageUpdated_at = loo_Json.StringOf("products[i].image.updated_at")
li_ImageWidth = loo_Json.IntOf("products[i].image.width")
li_ImageHeight = loo_Json.IntOf("products[i].image.height")
ls_ImageSrc = loo_Json.StringOf("products[i].image.src")
j = 0
li_Count_j = loo_Json.SizeOfArray("products[i].variants")
do while j < li_Count_j
loo_Json.J = j
li_Id = loo_Json.IntOf("products[i].variants[j].id")
li_Product_id = loo_Json.IntOf("products[i].variants[j].product_id")
ls_Title = loo_Json.StringOf("products[i].variants[j].title")
ls_Price = loo_Json.StringOf("products[i].variants[j].price")
ls_Sku = loo_Json.StringOf("products[i].variants[j].sku")
li_Position = loo_Json.IntOf("products[i].variants[j].position")
li_Grams = loo_Json.IntOf("products[i].variants[j].grams")
ls_Inventory_policy = loo_Json.StringOf("products[i].variants[j].inventory_policy")
li_Compare_at_price = loo_Json.IsNullOf("products[i].variants[j].compare_at_price")
ls_Fulfillment_service = loo_Json.StringOf("products[i].variants[j].fulfillment_service")
ls_Inventory_management = loo_Json.StringOf("products[i].variants[j].inventory_management")
ls_Option1 = loo_Json.StringOf("products[i].variants[j].option1")
li_Option2 = loo_Json.IsNullOf("products[i].variants[j].option2")
li_Option3 = loo_Json.IsNullOf("products[i].variants[j].option3")
ls_Created_at = loo_Json.StringOf("products[i].variants[j].created_at")
ls_Updated_at = loo_Json.StringOf("products[i].variants[j].updated_at")
li_Taxable = loo_Json.BoolOf("products[i].variants[j].taxable")
ls_Barcode = loo_Json.StringOf("products[i].variants[j].barcode")
li_Image_id = loo_Json.IntOf("products[i].variants[j].image_id")
li_Inventory_quantity = loo_Json.IntOf("products[i].variants[j].inventory_quantity")
li_Weight = loo_Json.IntOf("products[i].variants[j].weight")
ls_Weight_unit = loo_Json.StringOf("products[i].variants[j].weight_unit")
li_Old_inventory_quantity = loo_Json.IntOf("products[i].variants[j].old_inventory_quantity")
li_Requires_shipping = loo_Json.BoolOf("products[i].variants[j].requires_shipping")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("products[i].options")
do while j < li_Count_j
loo_Json.J = j
li_Id = loo_Json.IntOf("products[i].options[j].id")
li_Product_id = loo_Json.IntOf("products[i].options[j].product_id")
ls_Name = loo_Json.StringOf("products[i].options[j].name")
li_Position = loo_Json.IntOf("products[i].options[j].position")
k = 0
li_Count_k = loo_Json.SizeOfArray("products[i].options[j].values")
do while k < li_Count_k
loo_Json.K = k
ls_StrVal = loo_Json.StringOf("products[i].options[j].values[k]")
k = k + 1
loop
j = j + 1
loop
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
j = 0
li_Count_j = loo_Json.SizeOfArray("products[i].image.variant_ids")
do while j < li_Count_j
loo_Json.J = j
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",
// "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": [
// ]
// }
// }
// ]
// }
Write-Debug "Example Completed."
destroy loo_Rest
destroy loo_SbJson
destroy loo_Json