forked from harvesthq/harvest_api_samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harvest_api_sample.ps1
47 lines (33 loc) · 1.47 KB
/
harvest_api_sample.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#REQUIRES -Version 2.0
<#
.SYNOPSIS
A simple example of how to call the Harvest Time Tracking API with basic authentication to list projects.
.DESCRIPTION
Basic API demo. Use this sample as a starting point on how to connect, authenticate, and send requests
to the Harvest API from PowerShell. This is not a libary!
.NOTES
Author : Joakim Westin ([email protected])
Prerequisite : PowerShell V2 over Vista and upper.
#>
param(
[string]$account = 'subdomain',
[string]$username = '[email protected]',
[string]$password = 'yourpassword'
)
# Set the account specific URI
$uri = "https://$account.harvestapp.com/projects"
# Build the authorization header from username & password
$auth = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))
# Create the web client and set the required headers
$req = New-Object System.Net.WebClient
$req.Headers.Add('Content-Type', 'application/xml')
$req.Headers.Add('Accept', 'application/xml')
$req.Headers.Add('Authorization', $auth )
# Issue the reqest and store the rewturned XML in the
[xml]$result = $req.DownloadString($uri)
<#
Now the response is available for anything you may want to do with it in the $result variable. To simply
list the projects you can try this:
#>
# List all project names, code and notes using a Grid-View (or in whateer way you like)
$result.projects.project | select name, Code, Notes | Out-GridView