PowerBuilder
PowerBuilder
GetHarvest - Test Personal Access Token
See more GetHarvest Examples
Demonstrates how to test your GetHarvest Personal Access TokenChilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_Id
string ls_First_name
string ls_Last_name
string ls_Email
string ls_Telephone
string ls_Timezone
integer li_Weekly_capacity
integer li_Has_access_to_all_future_projects
integer li_Is_contractor
integer li_Is_admin
integer li_Is_project_manager
integer li_Can_see_rates
integer li_Can_create_projects
integer li_Can_create_invoices
integer li_Is_active
string ls_Created_at
string ls_Updated_at
string ls_Default_hourly_rate
string ls_Cost_rate
string ls_Avatar_url
integer i
integer li_Count_i
string ls_StrVal
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
loo_Http.SetRequestHeader("User-Agent","Harvest API Example")
loo_Http.SetRequestHeader("Harvest-Account-ID","ACCOUNT_ID")
loo_Http.SetRequestHeader("Authorization","Bearer ACCESS_TOKEN")
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Http.QuickGetSb("https://api.harvestapp.com/api/v2/users/me.json",loo_SbResponseBody)
if li_Success <> 1 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.LastResponseHeader
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// {
// "id": 2826142,
// "first_name": "Joe",
// "last_name": "Johnson",
// "email": "joe@example.com",
// "telephone": "",
// "timezone": "Central Time (US & Canada)",
// "weekly_capacity": 126000,
// "has_access_to_all_future_projects": false,
// "is_contractor": false,
// "is_admin": true,
// "is_project_manager": false,
// "can_see_rates": true,
// "can_create_projects": true,
// "can_create_invoices": true,
// "is_active": true,
// "created_at": "2019-06-06T15:57:58Z",
// "updated_at": "2019-06-06T15:58:32Z",
// "default_hourly_rate": 175.0,
// "cost_rate": 60.0,
// "roles": [
// "role1",
// "role2"
// ],
// "avatar_url": "https://d3s3969qhosaug.cloudfront.net/default-avatars/4d46.png?1559836678"
// }
// 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_Id = loo_JResp.IntOf("id")
ls_First_name = loo_JResp.StringOf("first_name")
ls_Last_name = loo_JResp.StringOf("last_name")
ls_Email = loo_JResp.StringOf("email")
ls_Telephone = loo_JResp.StringOf("telephone")
ls_Timezone = loo_JResp.StringOf("timezone")
li_Weekly_capacity = loo_JResp.IntOf("weekly_capacity")
li_Has_access_to_all_future_projects = loo_JResp.BoolOf("has_access_to_all_future_projects")
li_Is_contractor = loo_JResp.BoolOf("is_contractor")
li_Is_admin = loo_JResp.BoolOf("is_admin")
li_Is_project_manager = loo_JResp.BoolOf("is_project_manager")
li_Can_see_rates = loo_JResp.BoolOf("can_see_rates")
li_Can_create_projects = loo_JResp.BoolOf("can_create_projects")
li_Can_create_invoices = loo_JResp.BoolOf("can_create_invoices")
li_Is_active = loo_JResp.BoolOf("is_active")
ls_Created_at = loo_JResp.StringOf("created_at")
ls_Updated_at = loo_JResp.StringOf("updated_at")
ls_Default_hourly_rate = loo_JResp.StringOf("default_hourly_rate")
ls_Cost_rate = loo_JResp.StringOf("cost_rate")
ls_Avatar_url = loo_JResp.StringOf("avatar_url")
i = 0
li_Count_i = loo_JResp.SizeOfArray("roles")
do while i < li_Count_i
loo_JResp.I = i
ls_StrVal = loo_JResp.StringOf("roles[i]")
i = i + 1
loop
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp