PowerBuilder
PowerBuilder
Shopify GraphQL Simple Query (Get Shop Object)
See more Shopify Examples
Demonstrates a simple Shopify GraphQL query to get specific fields of the Shop object.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
string ls_Query
string ls_Url
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_ShopId
string ls_ShopName
string ls_ShopDescription
string ls_ShopEmail
integer li_CostRequestedQueryCost
integer li_CostActualQueryCost
string ls_CostThrottleStatusMaximumAvailable
integer li_CostThrottleStatusCurrentlyAvailable
string ls_CostThrottleStatusRestoreRate
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
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
// This example will use private authentication (which is HTTP Basic authentication)
// See the other Chilkat Shopify examples for OAuth2 authentication.
// 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
// We're going to do a POST https://{shop}.myshopify.com/admin/api/2021-04/graphql.json
// Make sure to replace "chilkat" with your store name.
// The body of the request will be:
// {
// shop {
// id
// name
// description
// email
// }
// }
// The above query is not JSON. It looks like JSON, but it's actually not.
// We'll just make it one line:
ls_Query = "{ shop { id name description email } }"
// My store name is "chilkat". Use your store name here instead.
ls_Url = "https://chilkat.myshopify.com/admin/api/2021-04/graphql.json"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpStr("POST",ls_Url,ls_Query,"utf-8","application/graphql",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
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "shop": {
// "id": "gid:\/\/shopify\/Shop\/24198053",
// "name": "chilkat",
// "description": null,
// "email": "admin@chilkatsoft.com"
// }
// },
// "extensions": {
// "cost": {
// "requestedQueryCost": 1,
// "actualQueryCost": 1,
// "throttleStatus": {
// "maximumAvailable": 1000.0,
// "currentlyAvailable": 999,
// "restoreRate": 50.0
// }
// }
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
ls_ShopId = loo_JResp.StringOf("data.shop.id")
ls_ShopName = loo_JResp.StringOf("data.shop.name")
ls_ShopDescription = loo_JResp.StringOf("data.shop.description")
ls_ShopEmail = loo_JResp.StringOf("data.shop.email")
li_CostRequestedQueryCost = loo_JResp.IntOf("extensions.cost.requestedQueryCost")
li_CostActualQueryCost = loo_JResp.IntOf("extensions.cost.actualQueryCost")
ls_CostThrottleStatusMaximumAvailable = loo_JResp.StringOf("extensions.cost.throttleStatus.maximumAvailable")
li_CostThrottleStatusCurrentlyAvailable = loo_JResp.IntOf("extensions.cost.throttleStatus.currentlyAvailable")
ls_CostThrottleStatusRestoreRate = loo_JResp.StringOf("extensions.cost.throttleStatus.restoreRate")
Write-Debug "Shop name: " + ls_ShopName
// ...
destroy loo_Http
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp