Sample code for 30+ languages & platforms
Xbase++

GetHarvest - Test Personal Access Token

See more GetHarvest Examples

Demonstrates how to test your GetHarvest Personal Access Token

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL nId
LOCAL cFirst_name
LOCAL cLast_name
LOCAL cEmail
LOCAL cTelephone
LOCAL cTimezone
LOCAL nWeekly_capacity
LOCAL nHas_access_to_all_future_projects
LOCAL nIs_contractor
LOCAL nIs_admin
LOCAL nIs_project_manager
LOCAL nCan_see_rates
LOCAL nCan_create_projects
LOCAL nCan_create_invoices
LOCAL nIs_active
LOCAL cCreated_at
LOCAL cUpdated_at
LOCAL cDefault_hourly_rate
LOCAL cCost_rate
LOCAL cAvatar_url
LOCAL i
LOCAL nCount_i
LOCAL cStrVal

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

oHttp:SetRequestHeader("User-Agent", "Harvest API Example")
oHttp:SetRequestHeader("Harvest-Account-ID", "ACCOUNT_ID")
oHttp:SetRequestHeader("Authorization", "Bearer ACCESS_TOKEN")

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.harvestapp.com/api/v2/users/me.json", oSbResponseBody)
IF (nSuccess != 1)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)

IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oHttp:LastResponseHeader
    oHttp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
ENDIF

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

nId := oJResp:IntOf("id")
cFirst_name := oJResp:StringOf("first_name")
cLast_name := oJResp:StringOf("last_name")
cEmail := oJResp:StringOf("email")
cTelephone := oJResp:StringOf("telephone")
cTimezone := oJResp:StringOf("timezone")
nWeekly_capacity := oJResp:IntOf("weekly_capacity")
nHas_access_to_all_future_projects := oJResp:BoolOf("has_access_to_all_future_projects")
nIs_contractor := oJResp:BoolOf("is_contractor")
nIs_admin := oJResp:BoolOf("is_admin")
nIs_project_manager := oJResp:BoolOf("is_project_manager")
nCan_see_rates := oJResp:BoolOf("can_see_rates")
nCan_create_projects := oJResp:BoolOf("can_create_projects")
nCan_create_invoices := oJResp:BoolOf("can_create_invoices")
nIs_active := oJResp:BoolOf("is_active")
cCreated_at := oJResp:StringOf("created_at")
cUpdated_at := oJResp:StringOf("updated_at")
cDefault_hourly_rate := oJResp:StringOf("default_hourly_rate")
cCost_rate := oJResp:StringOf("cost_rate")
cAvatar_url := oJResp:StringOf("avatar_url")
i := 0
nCount_i := oJResp:SizeOfArray("roles")
DO WHILE i < nCount_i
    oJResp:I := i
    cStrVal := oJResp:StringOf("roles[i]")
    i := i + 1
ENDDO

oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()