Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
GetHarvest - Test Personal Access Token
See more GetHarvest Examples
Demonstrates how to test your GetHarvest Personal Access TokenChilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.StringBuilder,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
sbResponseBody: TStringBuilder;
jResp: TJsonObject;
respStatusCode: Integer;
id: Integer;
first_name: string;
last_name: string;
email: string;
telephone: string;
timezone: string;
weekly_capacity: Integer;
has_access_to_all_future_projects: Boolean;
is_contractor: Boolean;
is_admin: Boolean;
is_project_manager: Boolean;
can_see_rates: Boolean;
can_create_projects: Boolean;
can_create_invoices: Boolean;
is_active: Boolean;
created_at: string;
updated_at: string;
default_hourly_rate: string;
cost_rate: string;
avatar_url: string;
i: Integer;
count_i: Integer;
strVal: string;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
http.SetRequestHeader('User-Agent','Harvest API Example');
http.SetRequestHeader('Harvest-Account-ID','ACCOUNT_ID');
http.SetRequestHeader('Authorization','Bearer ACCESS_TOKEN');
sbResponseBody := TStringBuilder.Create;
success := http.QuickGetSb('https://api.harvestapp.com/api/v2/users/me.json',sbResponseBody);
if (success <> True) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
jResp := TJsonObject.Create;
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact := False;
WriteLn('Response Body:');
WriteLn(jResp.Emit());
respStatusCode := http.LastStatus;
WriteLn('Response Status Code = ' + respStatusCode);
if (respStatusCode >= 400) then
begin
WriteLn('Response Header:');
WriteLn(http.LastResponseHeader);
Exit;
end;
// 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
id := jResp.IntOf('id');
first_name := jResp.StringOf('first_name');
last_name := jResp.StringOf('last_name');
email := jResp.StringOf('email');
telephone := jResp.StringOf('telephone');
timezone := jResp.StringOf('timezone');
weekly_capacity := jResp.IntOf('weekly_capacity');
has_access_to_all_future_projects := jResp.BoolOf('has_access_to_all_future_projects');
is_contractor := jResp.BoolOf('is_contractor');
is_admin := jResp.BoolOf('is_admin');
is_project_manager := jResp.BoolOf('is_project_manager');
can_see_rates := jResp.BoolOf('can_see_rates');
can_create_projects := jResp.BoolOf('can_create_projects');
can_create_invoices := jResp.BoolOf('can_create_invoices');
is_active := jResp.BoolOf('is_active');
created_at := jResp.StringOf('created_at');
updated_at := jResp.StringOf('updated_at');
default_hourly_rate := jResp.StringOf('default_hourly_rate');
cost_rate := jResp.StringOf('cost_rate');
avatar_url := jResp.StringOf('avatar_url');
i := 0;
count_i := jResp.SizeOfArray('roles');
while i < count_i do
begin
jResp.I := i;
strVal := jResp.StringOf('roles[i]');
i := i + 1;
end;
http.Free;
sbResponseBody.Free;
jResp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.