forked from jakmanne/api-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowershell_script.ps1
43 lines (32 loc) · 1.57 KB
/
powershell_script.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
# -- SETUP --
$userid= "***********"
$clientId = "**********************"
$secret = "*******"
# -- END SETUP --
$headers = @{}
$encodedClientId = [System.Web.HttpUtility]::UrlEncode($clientId)
$encodedSecret = [System.Web.HttpUtility]::UrlEncode($secret)
$credentials = "$($encodedClientId):$($encodedSecret)"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($credentials)
$EncodedText =[Convert]::ToBase64String($Bytes)
$headers.Add("Authorization", "Basic "+$EncodedText)
$headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
$headers.Add("Accept", "application/json")
$postParams = @{grant_type='client_credentials'}
$authResponse = Invoke-RestMethod -Uri "https://auth.sbanken.no/IdentityServer/connect/token" -Method POST -Headers $headers -Body $postParams
echo "Accounts ----"
$authHeaders = @{}
$authHeaders.Add("Accept", "application/json")
$authHeaders.Add("customerId", $userid);
$authHeaders.Add("Authorization", "Bearer "+$authResponse.access_token)
$accountUri = "https://api.sbanken.no/Bank/api/v1/Accounts"
$response = Invoke-RestMethod -Uri $accountUri -Method GET -Headers $authHeaders
$response
echo "Get spesific account based on AccountId"
$authHeaders = @{}
$authHeaders.Add("Accept", "application/json")
$authHeaders.Add("customerId", $userid);
$authHeaders.Add("Authorization", "Bearer "+$authResponse.access_token)
$accountUri = "https://api.sbanken.no/Bank/api/v1/Accounts/" + $response.items[0].accountId
$response = Invoke-RestMethod -Uri $accountUri -Method GET -Headers $authHeaders
$response