-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColleagueWebAPI_PoShClient.ps1
More file actions
94 lines (63 loc) · 2.04 KB
/
ColleagueWebAPI_PoShClient.ps1
File metadata and controls
94 lines (63 loc) · 2.04 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#region Authorization
$Credentials = @{
UserId='username'
Password='Hunter1'
} | ConvertTo-Json
$RootUri = "http://localhost:57276/"
#Get a new Colleague API Token
function Get-CollApiToken($Uri, $Credentials){
return Invoke-RestMethod -Method POST `
-Uri "$Uri/session/login" -Body $Credentials `
-ContentType "application/json"
}
#create the Colleague API Header with the provided token
function Get-CollApiHeader($Token){
return @{"X-CustomCredentials"=$Token}
}
#endregion
#region Delivered Examples
#Get a list of buildings - does not require authentication,
# good for testing connectivity
function Get-CollApiBuildings($Uri){
return Invoke-RestMethod -Method GET -Uri "$Uri/buildings"
}
#Get a list of majors - requires authentication
function Get-Majors($Uri, $Credentials){
$Token = Get-CollApiToken $Uri $Credentials
$Header = Get-CollApiHeader $Token
return Invoke-RestMethod -Method GET -Uri "$Uri/majors" -Headers $Header
}
#endregion
#region GET example
#Get from the example endpoint
function Get-WebAdvisorIdAndDate {
param (
$Uri,
$Credentials,
[string]$ColleagueId
)
$Token = Get-CollApiToken $Uri $Credentials
$Header = Get-CollApiHeader $Token
return Invoke-RestMethod -Method GET `
-Uri "$Uri/custom/WebAdvisorIdAndDate/$ColleagueId" `
-Headers $Header
}
#endregion
#region POST example
#Post to the example endpoint
function Post-WebAdvisorIdAndDate($Uri, $Credentials, $WaiddObj){
$Token = Get-CollApiToken $Uri $Credentials
$Header = Get-CollApiHeader $Token
Invoke-RestMethod -Method POST -Uri ("$Uri/custom/WebAdvisorIdAndDate") `
-Headers $Header `
-Body ($WaiddObj | ConvertTo-Json) `
-ContentType "application/json"
}
#endregion
<# Example Usage
#TO USE THE GET ENDPOINT
Get-WebAdvisorIdAndDate $RootUri $Credentials 0123456
#TO USE THE POST ENDPOINT
$WaiddObj = New-Object -TypeName psobject -Property @{"ColleagueId"="0123456"}
Post-WebAdvisorIdAndDate $RootUri $Credentials $WaiddObj
#>