Sample code for 30+ languages & platforms
DataFlex

Square API - List Catalog

See more Square Examples

Returns a list of CatalogObjects that includes all objects of a set of desired types (for example, all CatalogItem and CatalogTax objects) in the catalog.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sV_type
    String sId
    String sUpdated_at
    Integer iVersion
    Boolean iIs_deleted
    Boolean iPresent_at_all_locations
    String sCategory_dataName
    String sTax_dataName
    String sTax_dataCalculation_phase
    String sTax_dataInclusion_type
    String sTax_dataPercentage
    Boolean iTax_dataEnabled
    Integer i
    Integer iCount_i
    String sTemp1

    Move False To iSuccess

    // 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/list?types=category%2Ctax \
    //   -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.
    Set ComAuthToken Of hoHttp To "ACCESS_TOKEN"
    Send ComSetRequestHeader To hoHttp "Square-Version" "2020-07-22"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    // This example uses the sandbox: connect.squareupsandbox.com
    // Production should use connect.squareup.com
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComQuickGetSb Of hoHttp "https://connect.squareupsandbox.com/v2/catalog/list?types=item,category,tax,image" vSbResponseBody To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    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 ComLastStatus Of hoHttp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComLastHeader Of hoHttp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

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

    // {
    //   "objects": [
    //     {
    //       "type": "CATEGORY",
    //       "id": "5ZYQZZ2IECPVJ2IJ5KQPRDC3",
    //       "updated_at": "2017-02-21T14:50:26.495Z",
    //       "version": 1487688626495,
    //       "is_deleted": false,
    //       "present_at_all_locations": true,
    //       "category_data": {
    //         "name": "Beverages"
    //       }
    //     },
    //     {
    //       "type": "TAX",
    //       "id": "L5R47DGBZOOVKCAFIXC56AEN",
    //       "updated_at": "2017-02-21T14:50:26.495Z",
    //       "version": 1487688626495,
    //       "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

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "objects" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "objects[i].type" To sV_type
        Get ComStringOf Of hoJResp "objects[i].id" To sId
        Get ComStringOf Of hoJResp "objects[i].updated_at" To sUpdated_at
        Get ComIntOf Of hoJResp "objects[i].version" To iVersion
        Get ComBoolOf Of hoJResp "objects[i].is_deleted" To iIs_deleted
        Get ComBoolOf Of hoJResp "objects[i].present_at_all_locations" To iPresent_at_all_locations
        Get ComStringOf Of hoJResp "objects[i].category_data.name" To sCategory_dataName
        Get ComStringOf Of hoJResp "objects[i].tax_data.name" To sTax_dataName
        Get ComStringOf Of hoJResp "objects[i].tax_data.calculation_phase" To sTax_dataCalculation_phase
        Get ComStringOf Of hoJResp "objects[i].tax_data.inclusion_type" To sTax_dataInclusion_type
        Get ComStringOf Of hoJResp "objects[i].tax_data.percentage" To sTax_dataPercentage
        Get ComBoolOf Of hoJResp "objects[i].tax_data.enabled" To iTax_dataEnabled
        Move (i + 1) To i
    Loop



End_Procedure