Xbase++
Xbase++
Square API - Search Catalog Objects
See more Square Examples
Searches for CatalogObject of any types against supported search attribute values, excluding custom attribute values on items or item variations, against one or more of the specified query expressions,Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cV_type
LOCAL cId
LOCAL cUpdated_at
LOCAL nVersion
LOCAL nIs_deleted
LOCAL nPresent_at_all_locations
LOCAL cItem_dataName
LOCAL cItem_dataDescription
LOCAL cItem_dataCategory_id
LOCAL cItem_dataProduct_type
LOCAL cItem_dataVisibility
LOCAL j
LOCAL nCount_j
LOCAL cStrVal
LOCAL cItem_variation_dataItem_id
LOCAL cItem_variation_dataName
LOCAL nItem_variation_dataOrdinal
LOCAL nItem_variation_dataPrice_moneyAmount
LOCAL cItem_variation_dataPrice_moneyCurrency
LOCAL cItem_variation_dataPricing_type
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/search \
// -X POST \
// -H 'Square-Version: 2020-07-22' \
// -H 'Authorization: Bearer ACCESS_TOKEN' \
// -H 'Content-Type: application/json' \
// -d '{
// "object_types": [
// "ITEM"
// ],
// "query": {
// "prefix_query": {
// "attribute_name": "name",
// "attribute_prefix": "tea"
// }
// },
// "limit": 100
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "object_types": [
// "ITEM"
// ],
// "query": {
// "prefix_query": {
// "attribute_name": "name",
// "attribute_prefix": "tea"
// }
// },
// "limit": 100
// }
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("object_types[0]", "ITEM")
oJson:UpdateString("query.prefix_query.attribute_name", "name")
oJson:UpdateString("query.prefix_query.attribute_prefix", "tea")
oJson:UpdateInt("limit", 100)
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
oHttp:AuthToken := "ACCESS_TOKEN"
oHttp:SetRequestHeader("Square-Version", "2020-07-22")
// This example uses the sandbox: connect.squareupsandbox.com
// Production should use connect.squareup.com
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://connect.squareupsandbox.com/v2/catalog/search", oJson, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oResp:Header
? "Failed."
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "objects": [
// {
// "type": "ITEM",
// "id": "X5DZ5NWWAQ44CKBLKIFQGOWK",
// "updated_at": "2017-10-26T15:41:32.337Z",
// "version": 1509032492337,
// "is_deleted": false,
// "present_at_all_locations": true,
// "item_data": {
// "name": "Tea - Black",
// "description": "A delicious blend of black tea.",
// "category_id": "E7CLE5RZZ744BHWVQQEAHI2C",
// "product_type": "REGULAR",
// "tax_ids": [
// "ZXITPM6RWHZ7GZ7EIP3YKECM"
// ],
// "variations": [
// {
// "type": "ITEM_VARIATION",
// "id": "5GSZPX6EU7MM75S57OONG3V5",
// "updated_at": "2017-10-26T15:27:31.626Z",
// "version": 1509031651626,
// "is_deleted": false,
// "present_at_all_locations": true,
// "item_variation_data": {
// "item_id": "X5DZ5NWWAQ44CKBLKIFQGOWK",
// "name": "Regular",
// "ordinal": 1,
// "price_money": {
// "amount": 150,
// "currency": "USD"
// },
// "pricing_type": "FIXED_PRICING"
// }
// },
// {
// "type": "ITEM_VARIATION",
// "id": "XVLBN7DU6JTWHJTG5F265B43",
// "updated_at": "2017-10-26T15:27:31.626Z",
// "version": 1509031651626,
// "is_deleted": false,
// "present_at_all_locations": true,
// "item_variation_data": {
// "item_id": "X5DZ5NWWAQ44CKBLKIFQGOWK",
// "name": "Large",
// "ordinal": 2,
// "price_money": {
// "amount": 225,
// "currency": "USD"
// },
// "pricing_type": "FIXED_PRICING"
// }
// }
// ],
// "visibility": "PRIVATE"
// }
// },
// {
// "type": "ITEM",
// "id": "NNNEM3LA656Q46NXLWCNI7S5",
// "updated_at": "2017-10-26T15:41:23.232Z",
// "version": 1509032483232,
// "is_deleted": false,
// "present_at_all_locations": true,
// "item_data": {
// "name": "Tea - Green",
// "description": "Relaxing green herbal tea.",
// "category_id": "E7CLE5RZZ744BHWVQQEAHI2C",
// "product_type": "REGULAR",
// "tax_ids": [
// "ZXITPM6RWHZ7GZ7EIP3YKECM"
// ],
// "variations": [
// {
// "type": "ITEM_VARIATION",
// "id": "FHYBVIA6NVBCSOVETA62WEA4",
// "updated_at": "2017-10-26T15:29:00.524Z",
// "version": 1509031740524,
// "is_deleted": false,
// "present_at_all_locations": true,
// "item_variation_data": {
// "item_id": "NNNEM3LA656Q46NXLWCNI7S5",
// "name": "Regular",
// "ordinal": 1,
// "price_money": {
// "amount": 150,
// "currency": "USD"
// },
// "pricing_type": "FIXED_PRICING"
// }
// }
// ],
// "visibility": "PRIVATE"
// }
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
i := 0
nCount_i := oJResp:SizeOfArray("objects")
DO WHILE i < nCount_i
oJResp:I := i
cV_type := oJResp:StringOf("objects[i].type")
cId := oJResp:StringOf("objects[i].id")
cUpdated_at := oJResp:StringOf("objects[i].updated_at")
nVersion := oJResp:IntOf("objects[i].version")
nIs_deleted := oJResp:BoolOf("objects[i].is_deleted")
nPresent_at_all_locations := oJResp:BoolOf("objects[i].present_at_all_locations")
cItem_dataName := oJResp:StringOf("objects[i].item_data.name")
cItem_dataDescription := oJResp:StringOf("objects[i].item_data.description")
cItem_dataCategory_id := oJResp:StringOf("objects[i].item_data.category_id")
cItem_dataProduct_type := oJResp:StringOf("objects[i].item_data.product_type")
cItem_dataVisibility := oJResp:StringOf("objects[i].item_data.visibility")
j := 0
nCount_j := oJResp:SizeOfArray("objects[i].item_data.tax_ids")
DO WHILE j < nCount_j
oJResp:J := j
cStrVal := oJResp:StringOf("objects[i].item_data.tax_ids[j]")
j := j + 1
ENDDO
j := 0
nCount_j := oJResp:SizeOfArray("objects[i].item_data.variations")
DO WHILE j < nCount_j
oJResp:J := j
cV_type := oJResp:StringOf("objects[i].item_data.variations[j].type")
cId := oJResp:StringOf("objects[i].item_data.variations[j].id")
cUpdated_at := oJResp:StringOf("objects[i].item_data.variations[j].updated_at")
nVersion := oJResp:IntOf("objects[i].item_data.variations[j].version")
nIs_deleted := oJResp:BoolOf("objects[i].item_data.variations[j].is_deleted")
nPresent_at_all_locations := oJResp:BoolOf("objects[i].item_data.variations[j].present_at_all_locations")
cItem_variation_dataItem_id := oJResp:StringOf("objects[i].item_data.variations[j].item_variation_data.item_id")
cItem_variation_dataName := oJResp:StringOf("objects[i].item_data.variations[j].item_variation_data.name")
nItem_variation_dataOrdinal := oJResp:IntOf("objects[i].item_data.variations[j].item_variation_data.ordinal")
nItem_variation_dataPrice_moneyAmount := oJResp:IntOf("objects[i].item_data.variations[j].item_variation_data.price_money.amount")
cItem_variation_dataPrice_moneyCurrency := oJResp:StringOf("objects[i].item_data.variations[j].item_variation_data.price_money.currency")
cItem_variation_dataPricing_type := oJResp:StringOf("objects[i].item_data.variations[j].item_variation_data.pricing_type")
j := j + 1
ENDDO
i := i + 1
ENDDO
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()