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
(DataFlex) 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
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Boolean iSuccess Variant vReq Handle hoReq Handle hoJson Variant vResp Handle hoResp Variant vSbResponseBody Handle hoSbResponseBody Handle hoJResp Integer iRespStatusCode String sImageType String sImageId String sImageUpdated_at Integer iImageVersion Boolean iImageIs_deleted Boolean iImagePresent_at_all_locations String sImageImage_dataName String sImageImage_dataUrl String sImageImage_dataCaption String sTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // 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 Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Set ComHttpVerb Of hoReq To "POST" Set ComPath Of hoReq To "/v2/catalog/images" Set ComContentType Of hoReq To "multipart/form-data" Get ComAddFileForUpload2 Of hoReq "file" "/local/path/to/file.jpg" "image/jpeg" To iSuccess // Make sure to use an object_id for an already-existing catalog item. Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "idempotency_key" "528dea59-7bfb-43c1-bd48-4a6bba7dd61f86" To iSuccess Get ComUpdateString Of hoJson "object_id" "2PTZYUOFGGDMT75UZLHQAPAC" To iSuccess Get ComUpdateString Of hoJson "image.id" "#TEMP_ID" To iSuccess Get ComUpdateString Of hoJson "image.type" "IMAGE" To iSuccess Get ComUpdateString Of hoJson "image.image_data.caption" "A picture of a cup of coffee" To iSuccess Get ComEmit Of hoJson To sTemp1 Send ComAddParam To hoReq "request" sTemp1 Send ComAddHeader To hoReq "Expect" "100-continue" Send ComAddHeader To hoReq "Authorization" "Bearer ACCESS_TOKEN" Send ComAddHeader To hoReq "Accept" "application/json" Send ComAddHeader To hoReq "Square-Version" "2020-07-22" // This example uses the sandbox: connect.squareupsandbox.com // Production should use connect.squareup.com Get pvComObject of hoReq to vReq Get ComSynchronousRequest Of hoHttp "connect.squareupsandbox.com" 443 True vReq To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp // 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 Get ComStringOf Of hoJResp "image.type" To sImageType Get ComStringOf Of hoJResp "image.id" To sImageId Get ComStringOf Of hoJResp "image.updated_at" To sImageUpdated_at Get ComIntOf Of hoJResp "image.version" To iImageVersion Get ComBoolOf Of hoJResp "image.is_deleted" To iImageIs_deleted Get ComBoolOf Of hoJResp "image.present_at_all_locations" To iImagePresent_at_all_locations Get ComStringOf Of hoJResp "image.image_data.name" To sImageImage_dataName Get ComStringOf Of hoJResp "image.image_data.url" To sImageImage_dataUrl Get ComStringOf Of hoJResp "image.image_data.caption" To sImageImage_dataCaption End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.