Sample code for 30+ languages & platforms
DataFlex

GetHarvest - List Clients

See more GetHarvest Examples

Returns a list of your clients.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    Integer iPer_page
    Integer iTotal_pages
    Integer iTotal_entries
    String sNext_page
    String sPrevious_page
    Integer iPage
    String sLinksFirst
    String sLinksNext
    String sLinksPrevious
    String sLinksLast
    Integer i
    Integer iCount_i
    Integer iId
    String sName
    Boolean iIs_active
    String sAddress
    String sCreated_at
    String sUpdated_at
    String sCurrency
    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://api.harvestapp.com/v2/clients" \
    //   -H "Authorization: Bearer ACCESS_TOKEN" \
    //   -H "Harvest-Account-Id: ACCOUNT_ID" \
    //   -H "User-Agent: MyApp (yourname@example.com)"

    Send ComSetRequestHeader To hoHttp "User-Agent" "MyApp (yourname@example.com)"
    Send ComSetRequestHeader To hoHttp "Authorization" "Bearer ACCESS_TOKEN"
    Send ComSetRequestHeader To hoHttp "Harvest-Account-Id" "ACCOUNT_ID"

    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://api.harvestapp.com/v2/clients" 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:

    // {
    //   "clients": [
    //     {
    //       "id": 5735776,
    //       "name": "123 Industries",
    //       "is_active": true,
    //       "address": "123 Main St.\r\nAnytown, LA 71223",
    //       "created_at": "2017-06-26T21:02:12Z",
    //       "updated_at": "2017-06-26T21:34:11Z",
    //       "currency": "EUR"
    //     },
    //     {
    //       "id": 5735774,
    //       "name": "ABC Corp",
    //       "is_active": true,
    //       "address": "456 Main St.\r\nAnytown, CT 06467",
    //       "created_at": "2017-06-26T21:01:52Z",
    //       "updated_at": "2017-06-26T21:27:07Z",
    //       "currency": "USD"
    //     }
    //   ],
    //   "per_page": 100,
    //   "total_pages": 1,
    //   "total_entries": 2,
    //   "next_page": null,
    //   "previous_page": null,
    //   "page": 1,
    //   "links": {
    //     "first": "https://api.harvestapp.com/v2/clients?page=1&per_page=100",
    //     "next": null,
    //     "previous": null,
    //     "last": "https://api.harvestapp.com/v2/clients?page=1&per_page=100"
    //   }
    // }

    // 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 ComIntOf Of hoJResp "per_page" To iPer_page
    Get ComIntOf Of hoJResp "total_pages" To iTotal_pages
    Get ComIntOf Of hoJResp "total_entries" To iTotal_entries
    Get ComStringOf Of hoJResp "next_page" To sNext_page
    Get ComStringOf Of hoJResp "previous_page" To sPrevious_page
    Get ComIntOf Of hoJResp "page" To iPage
    Get ComStringOf Of hoJResp "links.first" To sLinksFirst
    Get ComStringOf Of hoJResp "links.next" To sLinksNext
    Get ComStringOf Of hoJResp "links.previous" To sLinksPrevious
    Get ComStringOf Of hoJResp "links.last" To sLinksLast
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "clients" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "clients[i].id" To iId
        Get ComStringOf Of hoJResp "clients[i].name" To sName
        Get ComBoolOf Of hoJResp "clients[i].is_active" To iIs_active
        Get ComStringOf Of hoJResp "clients[i].address" To sAddress
        Get ComStringOf Of hoJResp "clients[i].created_at" To sCreated_at
        Get ComStringOf Of hoJResp "clients[i].updated_at" To sUpdated_at
        Get ComStringOf Of hoJResp "clients[i].currency" To sCurrency
        Move (i + 1) To i
    Loop



End_Procedure