Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Shopify Get particular fields of a single productGet particular fields of a single product
$oRest = ObjCreate("Chilkat.Rest") Local $bSuccess $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) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.