Xbase++
Xbase++
WooCommerce List Products having SKU
See more WooCommerce Examples
Gets information for a product by SKU.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJarrResp
LOCAL nRespStatusCode
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// 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 := 1
oHttp:Login := "consumer_key"
oHttp:Password := "consumer_secret"
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oHttp:SetUrlVar("sku", "3386460107914")
// Use "https" or "http" depending on what your site needs.
nSuccess := oHttp:QuickGetSb("http://example.com/wp-json/wc/v3/products?sku={$sku}", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJarrResp := CreateObject("Chilkat.JsonArray")
oJarrResp:LoadSb(oSbResponseBody)
oJarrResp:EmitCompact := 0
? "Response Body:"
? oJarrResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()
RETURN
ENDIF
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()