PowerBuilder
PowerBuilder
Shopify Get particular fields of a single product
See more Shopify Examples
Get particular fields of a single productChilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
oleobject loo_SbJson
oleobject loo_Json
integer li_ProductId
string ls_ProductTitle
integer i
integer li_Count_i
integer li_Id
integer li_Product_id
integer li_Position
string ls_Created_at
string ls_Updated_at
integer li_Width
integer li_Height
string ls_Src
integer j
integer li_Count_j
integer 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/#{id}.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.
li_ProductId = loo_Json.IntOf("product.id")
ls_ProductTitle = loo_Json.StringOf("product.title")
i = 0
li_Count_i = loo_Json.SizeOfArray("product.images")
do while i < li_Count_i
loo_Json.I = i
li_Id = loo_Json.IntOf("product.images[i].id")
li_Product_id = loo_Json.IntOf("product.images[i].product_id")
li_Position = loo_Json.IntOf("product.images[i].position")
ls_Created_at = loo_Json.StringOf("product.images[i].created_at")
ls_Updated_at = loo_Json.StringOf("product.images[i].updated_at")
li_Width = loo_Json.IntOf("product.images[i].width")
li_Height = loo_Json.IntOf("product.images[i].height")
ls_Src = loo_Json.StringOf("product.images[i].src")
j = 0
li_Count_j = loo_Json.SizeOfArray("product.images[i].variant_ids")
do while j < li_Count_j
loo_Json.J = j
li_IntVal = loo_Json.IntOf("product.images[i].variant_ids[j]")
j = j + 1
loop
i = i + 1
loop
// A sample JSON response body that is parsed by the above code:
// {
// "product": {
// "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
// ]
// }
// ]
// }
// }
Write-Debug "Example Completed."
destroy loo_Rest
destroy loo_SbJson
destroy loo_Json