Xbase++
Xbase++
Square API - Retrieve Catalog Object
See more Square Examples
Returns a single CatalogItem as a CatalogObject based on the provided ID.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cStrVal
LOCAL cV_type
LOCAL cId
LOCAL cUpdated_at
LOCAL nVersion
LOCAL nIs_deleted
LOCAL nPresent_at_all_locations
LOCAL cItem_variation_dataItem_id
LOCAL cItem_variation_dataName
LOCAL nItem_variation_dataOrdinal
LOCAL cItem_variation_dataPricing_type
LOCAL nItem_variation_dataPrice_moneyAmount
LOCAL cItem_variation_dataPrice_moneyCurrency
LOCAL cCategory_dataName
LOCAL cTax_dataName
LOCAL cTax_dataCalculation_phase
LOCAL cTax_dataInclusion_type
LOCAL cTax_dataPercentage
LOCAL nTax_dataEnabled
LOCAL cObjectType
LOCAL cObjectId
LOCAL cObjectUpdated_at
LOCAL nObjectVersion
LOCAL nObjectIs_deleted
LOCAL nObjectPresent_at_all_locations
LOCAL cObjectItem_dataName
LOCAL cObjectItem_dataDescription
LOCAL cObjectItem_dataCategory_id
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// 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.
oHttp:AuthToken := "ACCESS_TOKEN"
oHttp:SetRequestHeader("Square-Version", "2020-07-22")
oHttp:SetRequestHeader("Content-Type", "application/json")
oHttp:SetUrlVar("id", "2PTZYUOFGGDMT75UZLHQAPAC")
// This example uses the sandbox: connect.squareupsandbox.com
// Production should use connect.squareup.com
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://connect.squareupsandbox.com/v2/catalog/object/{$id}?include_related_objects=true", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// 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
cObjectType := oJResp:StringOf("object.type")
cObjectId := oJResp:StringOf("object.id")
cObjectUpdated_at := oJResp:StringOf("object.updated_at")
nObjectVersion := oJResp:IntOf("object.version")
nObjectIs_deleted := oJResp:BoolOf("object.is_deleted")
nObjectPresent_at_all_locations := oJResp:BoolOf("object.present_at_all_locations")
cObjectItem_dataName := oJResp:StringOf("object.item_data.name")
cObjectItem_dataDescription := oJResp:StringOf("object.item_data.description")
cObjectItem_dataCategory_id := oJResp:StringOf("object.item_data.category_id")
i := 0
nCount_i := oJResp:SizeOfArray("object.item_data.tax_ids")
DO WHILE i < nCount_i
oJResp:I := i
cStrVal := oJResp:StringOf("object.item_data.tax_ids[i]")
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("object.item_data.variations")
DO WHILE i < nCount_i
oJResp:I := i
cV_type := oJResp:StringOf("object.item_data.variations[i].type")
cId := oJResp:StringOf("object.item_data.variations[i].id")
cUpdated_at := oJResp:StringOf("object.item_data.variations[i].updated_at")
nVersion := oJResp:IntOf("object.item_data.variations[i].version")
nIs_deleted := oJResp:BoolOf("object.item_data.variations[i].is_deleted")
nPresent_at_all_locations := oJResp:BoolOf("object.item_data.variations[i].present_at_all_locations")
cItem_variation_dataItem_id := oJResp:StringOf("object.item_data.variations[i].item_variation_data.item_id")
cItem_variation_dataName := oJResp:StringOf("object.item_data.variations[i].item_variation_data.name")
nItem_variation_dataOrdinal := oJResp:IntOf("object.item_data.variations[i].item_variation_data.ordinal")
cItem_variation_dataPricing_type := oJResp:StringOf("object.item_data.variations[i].item_variation_data.pricing_type")
nItem_variation_dataPrice_moneyAmount := oJResp:IntOf("object.item_data.variations[i].item_variation_data.price_money.amount")
cItem_variation_dataPrice_moneyCurrency := oJResp:StringOf("object.item_data.variations[i].item_variation_data.price_money.currency")
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("related_objects")
DO WHILE i < nCount_i
oJResp:I := i
cV_type := oJResp:StringOf("related_objects[i].type")
cId := oJResp:StringOf("related_objects[i].id")
cUpdated_at := oJResp:StringOf("related_objects[i].updated_at")
nVersion := oJResp:IntOf("related_objects[i].version")
nIs_deleted := oJResp:BoolOf("related_objects[i].is_deleted")
nPresent_at_all_locations := oJResp:BoolOf("related_objects[i].present_at_all_locations")
cCategory_dataName := oJResp:StringOf("related_objects[i].category_data.name")
cTax_dataName := oJResp:StringOf("related_objects[i].tax_data.name")
cTax_dataCalculation_phase := oJResp:StringOf("related_objects[i].tax_data.calculation_phase")
cTax_dataInclusion_type := oJResp:StringOf("related_objects[i].tax_data.inclusion_type")
cTax_dataPercentage := oJResp:StringOf("related_objects[i].tax_data.percentage")
nTax_dataEnabled := oJResp:BoolOf("related_objects[i].tax_data.enabled")
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()