-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInvoke-SFQuery.ps1
More file actions
60 lines (50 loc) · 1.55 KB
/
Invoke-SFQuery.ps1
File metadata and controls
60 lines (50 loc) · 1.55 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
$SFUsername = "username"
$SFPassword = "password"
$SFCompanyId = "CONTOSO"
$SFUrl = "https://api2.successfactors.eu"
function Invoke-SFAPIQuery {
param (
[parameter(Mandatory = $true)]
$Uri,
[parameter(Mandatory = $false)]
$Method = 'GET',
[parameter(Mandatory = $false)]
$Body
)
if($Uri.Contains("?")){
$Uri += '&$format=JSON'
}else{
$Uri += '?$format=JSON'
}
# Create an empty array to store the result.
$QueryResults = @()
# Invoke REST method and fetch data until there are no pages left.
do {
$params = @{
Headers = $global:headers
Uri = $Uri
UseBasicParsing = $true
Method = $Method
ContentType = "application/json"
}
if($Body -and $Body -is [hashtable]){
$params.Body = ConvertTo-Json -Depth 100 -InputObject $Body
}
$Results = Invoke-RestMethod @params
if($Results.d.results){
$QueryResults += $Results.d.results
}else{
$Results.d
}
$uri = $Results.d.__next
} until (!($uri))
# Return the result.
$QueryResults
}
# Get SF Entries
Invoke-SFAPIQuery -Uri "$global:SFUrl/odata/v2/EmpEmployment"
# Update SF Entry
Invoke-SFAPIQuery -Uri "$global:SFUrl/odata/v2/upsert?purgeType=incremental&suppressUpdateOfIdenticalData=true" -Method 'POST' -Body @{
"__metadata" = $Employee.__metadata
"username" = "john.doe"
}