Sample code for 30+ languages & platforms
PowerBuilder

Square API - Retrieve Catalog Object

See more Square Examples

Returns a single CatalogItem as a CatalogObject based on the provided ID.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_StrVal
string ls_V_type
string ls_Id
string ls_Updated_at
integer li_Version
integer li_Is_deleted
integer li_Present_at_all_locations
string ls_Item_variation_dataItem_id
string ls_Item_variation_dataName
integer li_Item_variation_dataOrdinal
string ls_Item_variation_dataPricing_type
integer li_Item_variation_dataPrice_moneyAmount
string ls_Item_variation_dataPrice_moneyCurrency
string ls_Category_dataName
string ls_Tax_dataName
string ls_Tax_dataCalculation_phase
string ls_Tax_dataInclusion_type
string ls_Tax_dataPercentage
integer li_Tax_dataEnabled
string ls_ObjectType
string ls_ObjectId
string ls_ObjectUpdated_at
integer li_ObjectVersion
integer li_ObjectIs_deleted
integer li_ObjectPresent_at_all_locations
string ls_ObjectItem_dataName
string ls_ObjectItem_dataDescription
string ls_ObjectItem_dataCategory_id
integer i
integer li_Count_i

li_Success = 0

// This example assumes 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

// Implements the following CURL command:

// curl https://connect.squareup.com/v2/catalog/object/W62UWFY35CWMYGVWK6TWJDNI?include_related_objects=true 
//   -H 'Square-Version: 2020-07-22' 
//   -H 'Authorization: Bearer ACCESS_TOKEN' 
//   -H 'Content-Type: application/json'

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
loo_Http.AuthToken = "ACCESS_TOKEN"
loo_Http.SetRequestHeader("Square-Version","2020-07-22")
loo_Http.SetRequestHeader("Content-Type","application/json")

loo_Http.SetUrlVar("id","2PTZYUOFGGDMT75UZLHQAPAC")

// This example uses the sandbox: connect.squareupsandbox.com
// Production should use connect.squareup.com
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://connect.squareupsandbox.com/v2/catalog/object/{$id}?include_related_objects=true",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

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_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "object": {
//     "type": "ITEM",
//     "id": "W62UWFY35CWMYGVWK6TWJDNI",
//     "updated_at": "2016-11-16T22:25:24.878Z",
//     "version": 1479335124878,
//     "is_deleted": false,
//     "present_at_all_locations": true,
//     "item_data": {
//       "name": "Tea",
//       "description": "Hot Leaf Juice",
//       "category_id": "BJNQCF2FJ6S6UIDT65ABHLRX",
//       "tax_ids": [
//         "HURXQOOAIC4IZSI2BEXQRYFY"
//       ],
//       "variations": [
//         {
//           "type": "ITEM_VARIATION",
//           "id": "2TZFAOHWGG7PAK2QEXWYPZSP",
//           "updated_at": "2016-11-16T22:25:24.878Z",
//           "version": 1479335124878,
//           "is_deleted": false,
//           "present_at_all_locations": true,
//           "item_variation_data": {
//             "item_id": "W62UWFY35CWMYGVWK6TWJDNI",
//             "name": "Mug",
//             "ordinal": 0,
//             "pricing_type": "FIXED_PRICING",
//             "price_money": {
//               "amount": 150,
//               "currency": "USD"
//             }
//           }
//         }
//       ]
//     }
//   },
//   "related_objects": [
//     {
//       "type": "CATEGORY",
//       "id": "BJNQCF2FJ6S6UIDT65ABHLRX",
//       "updated_at": "2016-11-16T22:25:24.878Z",
//       "version": 1479335124878,
//       "is_deleted": false,
//       "present_at_all_locations": true,
//       "category_data": {
//         "name": "Beverages"
//       }
//     },
//     {
//       "type": "TAX",
//       "id": "HURXQOOAIC4IZSI2BEXQRYFY",
//       "updated_at": "2016-11-16T22:25:24.878Z",
//       "version": 1479335124878,
//       "is_deleted": false,
//       "present_at_all_locations": true,
//       "tax_data": {
//         "name": "Sales Tax",
//         "calculation_phase": "TAX_SUBTOTAL_PHASE",
//         "inclusion_type": "ADDITIVE",
//         "percentage": "5.0",
//         "enabled": true
//       }
//     }
//   ]
// }

// 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_ObjectType = loo_JResp.StringOf("object.type")
ls_ObjectId = loo_JResp.StringOf("object.id")
ls_ObjectUpdated_at = loo_JResp.StringOf("object.updated_at")
li_ObjectVersion = loo_JResp.IntOf("object.version")
li_ObjectIs_deleted = loo_JResp.BoolOf("object.is_deleted")
li_ObjectPresent_at_all_locations = loo_JResp.BoolOf("object.present_at_all_locations")
ls_ObjectItem_dataName = loo_JResp.StringOf("object.item_data.name")
ls_ObjectItem_dataDescription = loo_JResp.StringOf("object.item_data.description")
ls_ObjectItem_dataCategory_id = loo_JResp.StringOf("object.item_data.category_id")
i = 0
li_Count_i = loo_JResp.SizeOfArray("object.item_data.tax_ids")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("object.item_data.tax_ids[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("object.item_data.variations")
do while i < li_Count_i
    loo_JResp.I = i
    ls_V_type = loo_JResp.StringOf("object.item_data.variations[i].type")
    ls_Id = loo_JResp.StringOf("object.item_data.variations[i].id")
    ls_Updated_at = loo_JResp.StringOf("object.item_data.variations[i].updated_at")
    li_Version = loo_JResp.IntOf("object.item_data.variations[i].version")
    li_Is_deleted = loo_JResp.BoolOf("object.item_data.variations[i].is_deleted")
    li_Present_at_all_locations = loo_JResp.BoolOf("object.item_data.variations[i].present_at_all_locations")
    ls_Item_variation_dataItem_id = loo_JResp.StringOf("object.item_data.variations[i].item_variation_data.item_id")
    ls_Item_variation_dataName = loo_JResp.StringOf("object.item_data.variations[i].item_variation_data.name")
    li_Item_variation_dataOrdinal = loo_JResp.IntOf("object.item_data.variations[i].item_variation_data.ordinal")
    ls_Item_variation_dataPricing_type = loo_JResp.StringOf("object.item_data.variations[i].item_variation_data.pricing_type")
    li_Item_variation_dataPrice_moneyAmount = loo_JResp.IntOf("object.item_data.variations[i].item_variation_data.price_money.amount")
    ls_Item_variation_dataPrice_moneyCurrency = loo_JResp.StringOf("object.item_data.variations[i].item_variation_data.price_money.currency")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("related_objects")
do while i < li_Count_i
    loo_JResp.I = i
    ls_V_type = loo_JResp.StringOf("related_objects[i].type")
    ls_Id = loo_JResp.StringOf("related_objects[i].id")
    ls_Updated_at = loo_JResp.StringOf("related_objects[i].updated_at")
    li_Version = loo_JResp.IntOf("related_objects[i].version")
    li_Is_deleted = loo_JResp.BoolOf("related_objects[i].is_deleted")
    li_Present_at_all_locations = loo_JResp.BoolOf("related_objects[i].present_at_all_locations")
    ls_Category_dataName = loo_JResp.StringOf("related_objects[i].category_data.name")
    ls_Tax_dataName = loo_JResp.StringOf("related_objects[i].tax_data.name")
    ls_Tax_dataCalculation_phase = loo_JResp.StringOf("related_objects[i].tax_data.calculation_phase")
    ls_Tax_dataInclusion_type = loo_JResp.StringOf("related_objects[i].tax_data.inclusion_type")
    ls_Tax_dataPercentage = loo_JResp.StringOf("related_objects[i].tax_data.percentage")
    li_Tax_dataEnabled = loo_JResp.BoolOf("related_objects[i].tax_data.enabled")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp