(PureBasic) Shopware Digest Authentication
Demonstrates using Digest access authentication for Shopware. For more information, see https://developers.shopware.com/developers-guide/rest-api/#digest-access-authentication
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; To use HTTP Digest Authentication, set the login and password, and also indicate that DigestAuth should be used.
CkHttp::setCkLogin(http, "api_username")
CkHttp::setCkPassword(http, "api_key")
CkHttp::setCkDigestAuth(http, 1)
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkHttp::ckQuickGetSb(http,"https://my-shopware-shop.com/api/articles?limit=2",sbResponseBody)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,sbResponseBody)
CkJsonObject::setCkEmitCompact(jResp, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(jResp)
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
|