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) Square API - Create Catalog ImageUploads an image file to be represented by an CatalogImage object linked to an existing CatalogObject instance. For more information, see https://developer.squareup.com/reference/square/catalog-api/create-catalog-image
integer li_rc oleobject loo_Http integer li_Success oleobject loo_Req oleobject loo_Json oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_ImageType string ls_ImageId string ls_ImageUpdated_at integer li_ImageVersion integer li_ImageIs_deleted integer li_ImagePresent_at_all_locations string ls_ImageImage_dataName string ls_ImageImage_dataUrl string ls_ImageImage_dataCaption // This example assumes 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 // Implements the following CURL command: // curl https://connect.squareup.com/v2/catalog/images \ // -X POST \ // -H 'Square-Version: 2020-07-22' \ // -H 'Authorization: Bearer ACCESS_TOKEN' \ // -H 'Accept: application/json' \ // -F 'file=@/local/path/to/file.jpg' \ // -F 'request={ // "idempotency_key": "528dea59-7bfb-43c1-bd48-4a6bba7dd61f86", // "object_id": "ND6EA5AAJEO5WL3JNNIAQA32", // "image": { // "id": "#TEMP_ID", // "type": "IMAGE", // "image_data": { // "caption": "A picture of a cup of coffee" // } // } // }' // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code loo_Req = create oleobject // Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") loo_Req.HttpVerb = "POST" loo_Req.Path = "/v2/catalog/images" loo_Req.ContentType = "multipart/form-data" li_Success = loo_Req.AddFileForUpload2("file","/local/path/to/file.jpg","image/jpeg") // Make sure to use an object_id for an already-existing catalog item. loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateString("idempotency_key","528dea59-7bfb-43c1-bd48-4a6bba7dd61f86") loo_Json.UpdateString("object_id","2PTZYUOFGGDMT75UZLHQAPAC") loo_Json.UpdateString("image.id","#TEMP_ID") loo_Json.UpdateString("image.type","IMAGE") loo_Json.UpdateString("image.image_data.caption","A picture of a cup of coffee") loo_Req.AddParam("request",loo_Json.Emit()) loo_Req.AddHeader("Expect","100-continue") loo_Req.AddHeader("Authorization","Bearer ACCESS_TOKEN") loo_Req.AddHeader("Accept","application/json") loo_Req.AddHeader("Square-Version","2020-07-22") // This example uses the sandbox: connect.squareupsandbox.com // Production should use connect.squareup.com loo_Resp = loo_Http.SynchronousRequest("connect.squareupsandbox.com",443,1,loo_Req) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Req destroy loo_Json 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_Req destroy loo_Json 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) // { // "image": { // "type": "IMAGE", // "id": "UBXKMBQ4QK47QXMNQD6ELCZT", // "updated_at": "2020-08-07T15:20:09.779Z", // "version": 1596813609779, // "is_deleted": false, // "present_at_all_locations": true, // "image_data": { // "name": "", // "url": "https://square-catalog-sandbox.s3.amazonaws.com/files/168973eab6f8b39b5cbdad52e3f82b23be196e2b/original.jpeg", // "caption": "A picture of a cup of coffee" // } // } // } // 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_ImageType = loo_JResp.StringOf("image.type") ls_ImageId = loo_JResp.StringOf("image.id") ls_ImageUpdated_at = loo_JResp.StringOf("image.updated_at") li_ImageVersion = loo_JResp.IntOf("image.version") li_ImageIs_deleted = loo_JResp.BoolOf("image.is_deleted") li_ImagePresent_at_all_locations = loo_JResp.BoolOf("image.present_at_all_locations") ls_ImageImage_dataName = loo_JResp.StringOf("image.image_data.name") ls_ImageImage_dataUrl = loo_JResp.StringOf("image.image_data.url") ls_ImageImage_dataCaption = loo_JResp.StringOf("image.image_data.caption") destroy loo_Http destroy loo_Req destroy loo_Json destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.