forked from kine/NVRAppDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Patch-BCAPIData.ps1
51 lines (49 loc) · 1.72 KB
/
Patch-BCAPIData.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
47
48
49
50
51
function Patch-BCAPIData
{
<#
.SYNOPSIS
Gets data from API
.DESCRIPTION
Use the OAuth bearer token and read data from given API
.PARAMETER OAuthToken
Result of calling e.g. Get-OAuth2 function
.PARAMETER APIURI
URI of the API to call (e.g. 'api/microsoft/automation/beta')
.PARAMETER Tenant
Tenant ID and environment name (e.g. 'mytenant' or 'mytenant/Sandbox')
.PARAMETER Query
Query part of the URL (e.g. 'companies')
.PARAMETER Body
Body of the query (e.g. app filen content)
.EXAMPLE
Patch-BCAPIData -OAuthToken $OAuth -APIURI 'api/microsoft/automation/beta' -Tenant 'mytenant/Sandbox' -Query 'companies("companyid")/extensionUpload(0)/content' -Body (Get-Content -Path myapp.app) -ContentType 'application/octet-stream'
#>
param(
[parameter(Mandatory = $true)]
$OAuthToken,
[parameter(Mandatory = $true)]
$APIURI,
[parameter(Mandatory = $true)]
$Tenant,
[parameter(Mandatory = $true)]
$Query,
[parameter(Mandatory = $true)]
$Body,
$ContentType='application/octet-stream',
$eTag='*',
$APIVersion = 'v1.0',
$Environment = ''
)
if ($Environment -ne '') {
$Tenant = $Tenant + '/' + $Environment
}
$Uri = "https://api.businesscentral.dynamics.com/$APIVersion/$Tenant/$APIURI/$Query"
$Headers = @{
Authorization = $OAuthToken.token_type + " " + $OAuthToken.access_token
'Content-Type' = $ContentType
'If-Match' = $eTag
}
Write-Verbose "PATCH $Uri"
$Result = Invoke-RestMethod -Method Patch -Uri $Uri -Headers $Headers -Body $Body
return $Result.value
}