PowerBuilder
PowerBuilder
Shopify Private Authentication for Private Apps
See more Shopify Examples
Shopify private authentication is for interacting with your own store through private applications. It uses HTTP "Basic" authentication with your Shopify private application key and secret key.This example demonstrates how to send a private authenticated request using Chilkat Http, and then the same using Chilkat Rest.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_SbJson
oleobject loo_Json
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First demonstrate sending a simple request using Shopify private authentication w/ the Chilkat Http API.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// To use HTTP Basic Authentication with any HTTP request, we simply set the Login, Password, and BasicAuth properties.
// Important: All HTTP requests using Basic authentication must be over SSL/TLS.
loo_Http.Login = "SHOPIFY_PRIVATE_API_KEY"
loo_Http.Password = "SHOPIFY_PRIVATE_API_SECRET_KEY"
loo_Http.BasicAuth = 1
// Make sure to replace "chilkat" with your store name.
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpNoBody("GET","https://chilkat.myshopify.com/admin/products.json",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Resp
return
end if
// Examine the response code.
if loo_Resp.StatusCode <> 200 then
Write-Debug "Received error response code: " + string(loo_Resp.StatusCode)
Write-Debug "Response body:"
Write-Debug loo_Resp.BodyStr
destroy loo_Http
destroy loo_Resp
return
end if
// Success.
Write-Debug "Success."
// Examine the JSON response
loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbJson)
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.LoadSb(loo_SbJson)
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()
// -------------------------------------------------
// Now let's do the same using the Chilkat Rest API.
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
// Provide the private app credentials:
loo_Rest.SetAuthBasic("SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_SECRET_KEY")
// Connect to the shopify server.
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
// Make sure to replace "chilkat" with your store name.
li_Success = loo_Rest.Connect("chilkat.myshopify.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Http
destroy loo_Resp
destroy loo_SbJson
destroy loo_Json
destroy loo_Rest
return
end if
loo_SbJson.Clear()
li_Success = loo_Rest.FullRequestNoBodySb("GET","/admin/products.json",loo_SbJson)
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Http
destroy loo_Resp
destroy loo_SbJson
destroy loo_Json
destroy loo_Rest
return
end if
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
Write-Debug "Response body:"
Write-Debug loo_SbJson.GetAsString()
destroy loo_Http
destroy loo_Resp
destroy loo_SbJson
destroy loo_Json
destroy loo_Rest
return
end if
// Success...
loo_Json.LoadSb(loo_SbJson)
Write-Debug loo_Json.Emit()
destroy loo_Http
destroy loo_Resp
destroy loo_SbJson
destroy loo_Json
destroy loo_Rest