AutoIt
AutoIt
Shopify Get all products, showing only some attributes
See more Shopify Examples
Get all products, showing only some attributesChilkat 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.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 $i
Local $iCount_i
Local $id
Local $sTitle
Local $iJ
Local $iCount_j
Local $iProduct_id
Local $iPosition
Local $sCreated_at
Local $sUpdated_at
Local $iWidth
Local $iHeight
Local $src
Local $iK
Local $iCount_k
Local $intVal
$i = 0
$iCount_i = $oJson.SizeOfArray("products")
While $i < $iCount_i
$oJson.I = $i
$id = $oJson.IntOf("products[i].id")
$sTitle = $oJson.StringOf("products[i].title")
$iJ = 0
$iCount_j = $oJson.SizeOfArray("products[i].images")
While $iJ < $iCount_j
$oJson.J = $iJ
$id = $oJson.IntOf("products[i].images[j].id")
$iProduct_id = $oJson.IntOf("products[i].images[j].product_id")
$iPosition = $oJson.IntOf("products[i].images[j].position")
$sCreated_at = $oJson.StringOf("products[i].images[j].created_at")
$sUpdated_at = $oJson.StringOf("products[i].images[j].updated_at")
$iWidth = $oJson.IntOf("products[i].images[j].width")
$iHeight = $oJson.IntOf("products[i].images[j].height")
$src = $oJson.StringOf("products[i].images[j].src")
$iK = 0
$iCount_k = $oJson.SizeOfArray("products[i].images[j].variant_ids")
While $iK < $iCount_k
$oJson.K = $iK
$intVal = $oJson.IntOf("products[i].images[j].variant_ids[k]")
$iK = $iK + 1
Wend
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend
; 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": [
; ]
; }
; ]
; }
ConsoleWrite("Example Completed." & @CRLF)