Sample code for 30+ languages & platforms
PowerBuilder

GetHarvest - List Clients

See more GetHarvest Examples

Returns a list of your clients.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
long li_RespStatusCode
long li_Per_page
long li_Total_pages
long li_Total_entries
string ls_Next_page
string ls_Previous_page
long li_Page
string ls_LinksFirst
string ls_LinksNext
string ls_LinksPrevious
string ls_LinksLast
long i
long li_Count_i
long li_Id
string ls_Name
long li_Is_active
string ls_Address
string ls_Created_at
string ls_Updated_at
string ls_Currency

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://api.harvestapp.com/v2/clients" \
//    -H "Authorization: Bearer ACCESS_TOKEN" \
//    -H "Harvest-Account-Id: ACCOUNT_ID" \
//    -H "User-Agent: MyApp (yourname@example.com)"

loo_Http.SetRequestHeader("User-Agent","MyApp (yourname@example.com)")
loo_Http.SetRequestHeader("Authorization","Bearer ACCESS_TOKEN")
loo_Http.SetRequestHeader("Harvest-Account-Id","ACCOUNT_ID")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://api.harvestapp.com/v2/clients",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:

//  {
//    "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

li_Per_page = loo_JResp.IntOf("per_page")
li_Total_pages = loo_JResp.IntOf("total_pages")
li_Total_entries = loo_JResp.IntOf("total_entries")
ls_Next_page = loo_JResp.StringOf("next_page")
ls_Previous_page = loo_JResp.StringOf("previous_page")
li_Page = loo_JResp.IntOf("page")
ls_LinksFirst = loo_JResp.StringOf("links.first")
ls_LinksNext = loo_JResp.StringOf("links.next")
ls_LinksPrevious = loo_JResp.StringOf("links.previous")
ls_LinksLast = loo_JResp.StringOf("links.last")
i = 0
li_Count_i = loo_JResp.SizeOfArray("clients")
do while i < li_Count_i
    loo_JResp.I = i
    li_Id = loo_JResp.IntOf("clients[i].id")
    ls_Name = loo_JResp.StringOf("clients[i].name")
    li_Is_active = loo_JResp.BoolOf("clients[i].is_active")
    ls_Address = loo_JResp.StringOf("clients[i].address")
    ls_Created_at = loo_JResp.StringOf("clients[i].created_at")
    ls_Updated_at = loo_JResp.StringOf("clients[i].updated_at")
    ls_Currency = loo_JResp.StringOf("clients[i].currency")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp