Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Shopify GraphQL Simple Query (Get Shop Object)See more Shopify ExamplesDemonstrates a simple Shopify GraphQL query to get specific fields of the Shop object. For more information, see https://www.shopify.com/partners/blog/shopify-graphql-learning-kit#query-structure
integer li_rc 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 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 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 = loo_Http.PText("POST",ls_Url,ls_Query,"utf-8","application/graphql",0,0) if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText destroy loo_Http 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_Resp destroy loo_Http return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 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_Resp destroy loo_Http destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // 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_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.