(AutoIt) WooCommerce List Products having SKU
Gets information for a product by SKU. For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
; Implements the following CURL command:
; curl https://example.com/wp-json/wc/v3/products?sku=3386460107914 \
; -u consumer_key:consumer_secret
; Use the following online tool to generate HTTP code from a CURL command
; Convert a cURL Command to HTTP Source Code
$oHttp.BasicAuth = True
$oHttp.Login = "consumer_key"
$oHttp.Password = "consumer_secret"
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oHttp.SetUrlVar("sku","3386460107914")
; Use "https" or "http" depending on what your site needs.
$bSuccess = $oHttp.QuickGetSb("http://example.com/wp-json/wc/v3/products?sku={$sku}",$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJarrResp = ObjCreate("Chilkat.JsonArray")
$oJarrResp.LoadSb($oSbResponseBody)
$oJarrResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJarrResp.Emit() & @CRLF)
Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oHttp.LastHeader & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
|