Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
GET /api/MT4/{tradePlatform}/UserRecordGet/{login}

Replace {tradePlatform}  with real identifierand {login} with real identifiers.


Expand
titleComplete PowerShell example
Code Block
languagepowershell
 # Flows :: ClientCredentials

$VerbosePreference = [System.Management.Automation.ActionPreference]::Continue

$ass = [Reflection.Assembly]::LoadFile("\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll")
$ass = [Reflection.Assembly]::LoadWithPartialName("System.Net.Http")
$ass = [Reflection.Assembly]::LoadWithPartialName("System.IdentityModel")
$ass = [Reflection.Assembly]::LoadFile("\packages\IdentityModel.1.3.1\lib\net45\IdentityModel.Net45.dll")

$IdSrvURI = "https://auth.cplugin.net"
$apiURI = "https://mywebapi.com"

$clientId="<put your client id here>"
$clientSecret="<put your client secret here>"

#orgs:
$org_cplugin = "<put your organization id here>"

#mt4:
$tp = "<put your trade platform id here>"

'==> authenticating...' | Write-Host -BackgroundColor Black
$client = new-object IdentityModel.Client.TokenClient `
    (($IdSrvURI+"/connect/token"), $clientId, $clientSecret, [IdentityModel.Client.AuthenticationStyle]::BasicAuthentication)
#$client | Format-List

$ct = new-object System.Threading.CancellationToken
$authResult = [IdentityModel.Client.TokenClientExtensions]::RequestClientCredentialsAsync(`
    $client, "webapi", $null, $ct).Result
'==> done!' | Write-Host -BackgroundColor Black

"authResult:" | Write-Host -BackgroundColor Black
$authResult | Format-List 

$auth_headers = @{
    "Authorization" = "Bearer " + $authResult.AccessToken
}

function rest_get($url)
{
    #$url | Write-Host -BackgroundColor Black
    Invoke-RestMethod -Uri ($apiURI + $url)  -ContentType "application/json" -Headers $auth_headers -Verbose -MaximumRedirection 0
    ($url + " done") | Write-Verbose
}

function rest_get_single($url)
{
    "Result: " + (rest_get $url)
}

function rest_get_list($url)
{
    (rest_get $url).value | Format-List
}

function rest_get_table($url)
{
    (rest_get $url).value | Format-Table
}

function rest_put($url, $data = $null)
{
    #$url | Write-Host -BackgroundColor Black
    Invoke-RestMethod -Method Put -Uri ($apiURI + $url)  -ContentType "application/json" -Headers $auth_headers -Verbose -MaximumRedirection 0 | Format-List
    ($url + " done") | Write-Verbose
}

function rest_post($url, $data = $null)
{
    #$url | Write-Host -BackgroundColor Black
    Invoke-RestMethod -Method Post -Uri ($apiURI + $url)  -ContentType "application/json" -Headers $auth_headers -Verbose -MaximumRedirection 0 | Format-List
    ($url + " done") | Write-Verbose
}

rest_get_list "/API/Organizations"
rest_get_list "/API/TradePlatforms"
rest_get_list "/API/MT4/$tp/UsersGet"

...