AutoIt
AutoIt
Shopify Get particular fields of a single product
See more Shopify Examples
Get particular fields of a single productChilkat AutoIt Downloads
Local $bSuccess = False
$oRest = ObjCreate("Chilkat.Rest")
$oRest.SetAuthBasic("SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_KEY")
$bSuccess = $oRest.Connect("chilkat.myshopify.com",443,True,True)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
$oSbJson = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestNoBodySb("GET","/admin/products/#{id}.json?fields=id,images,title",$oSbJson)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
If ($oRest.ResponseStatusCode <> 200) Then
ConsoleWrite("Received error response code: " & $oRest.ResponseStatusCode & @CRLF)
ConsoleWrite("Response body:" & @CRLF)
ConsoleWrite($oSbJson.GetAsString() & @CRLF)
Exit
EndIf
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.LoadSb($oSbJson)
; The following code parses the JSON response.
; A sample JSON response is shown below the sample code.
Local $iProductId
Local $sProductTitle
Local $i
Local $iCount_i
Local $id
Local $iProduct_id
Local $iPosition
Local $sCreated_at
Local $sUpdated_at
Local $iWidth
Local $iHeight
Local $src
Local $iJ
Local $iCount_j
Local $intVal
$iProductId = $oJson.IntOf("product.id")
$sProductTitle = $oJson.StringOf("product.title")
$i = 0
$iCount_i = $oJson.SizeOfArray("product.images")
While $i < $iCount_i
$oJson.I = $i
$id = $oJson.IntOf("product.images[i].id")
$iProduct_id = $oJson.IntOf("product.images[i].product_id")
$iPosition = $oJson.IntOf("product.images[i].position")
$sCreated_at = $oJson.StringOf("product.images[i].created_at")
$sUpdated_at = $oJson.StringOf("product.images[i].updated_at")
$iWidth = $oJson.IntOf("product.images[i].width")
$iHeight = $oJson.IntOf("product.images[i].height")
$src = $oJson.StringOf("product.images[i].src")
$iJ = 0
$iCount_j = $oJson.SizeOfArray("product.images[i].variant_ids")
While $iJ < $iCount_j
$oJson.J = $iJ
$intVal = $oJson.IntOf("product.images[i].variant_ids[j]")
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend
; 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
; ]
; }
; ]
; }
; }
ConsoleWrite("Example Completed." & @CRLF)