-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChurchCRM.psm1
70 lines (55 loc) · 1.55 KB
/
ChurchCRM.psm1
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
Function Connect-CCRMService
{
<#
.SYNOPSIS
Connects to the ChurchCRM API.
.PARAMETER URL
The URL of the ChurchCRM instance
.PARAMETER user
The User Name
.PARAMETER encodedPassword
The password
#>
Param(
$URL,
$UserName,
$Password
)
Set-Variable -Scope Global -Name "CRMURL" -Value $URL
Set-Variable -Scope Global -Name "CRMUsername" -Value $UserName
Set-Variable -Scope Global -Name "CRMPassword" -Value $Password
Invoke-WebRequest -Uri "$URL/Login.php" -Method "POST" -Body "User=$UserName&Password=$Password" -SessionVariable CRMSession
Set-Variable -Scope Global -Name "CRMSession" -Value $CRMSession
}
Function Invoke-CRMRESTMethod
{
param(
$EndpointURL,
$Method = "GET",
$Page=1,
[System.Collections.Hashtable]
$Parameters=@{}
)
if ( (test-path variable:global:"CRMURL") -and (test-path variable:global:"CRMSession") )
{
$URI = "$($(Get-Variable -Name "CRMURL").Value)/api/$($EndpointURL)"
if ($parameterString)
{
$URI +="?$($parameterString)"
}
Invoke-RestMethod -uri $URI -Method $Method -WebSession $($(Get-Variable -Name "CRMSession").value)
}
else
{
throw "CRMURL and CRMSession Required"
}
}
Function Get-CCRMPeople
{
param(
$searchTerm
)
$a = Invoke-CRMRESTMethod -EndpointURL "persons/search/$searchTerm" |
ConvertFrom-Json
$a | Select-Object -ExpandProperty persons
}