Brief
This is a standard RESTful JSON WebAPI.
Before making any calls to WebAPI you need to be authenticated.
Authentication
Once you get authorized you shall pass token within each call inside HTTP headers.
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjE0M2U4MjljMmI1NzQ4OTk2OTc1M2JhNGY4MjA1OTc5ZGYwZGE5ODh......<truncated for clarity>
To understand with what MT4/MT5 server you are going to work we have unique identifier assigned to each trade platform you registered at Admin portal → Trade platforms (https://admin.cplugin.net/TradePlatforms). There you choose type of this trade platform: MT4, MT5, etc. So, WebAPI will use right MetaQuotes Manager API.
Each trade platform has unique ID.
Controllers might require you to pass this TradePlatformID which can be obtained once (and saved locally to save time).
To get a list of all trade platforms available for you with its identifiers request this list using method: https://cloud.mywebapi.com/swagger/ui/index#!/TradePlatforms/TradePlatforms_Get
So, get it and pass it where is supposed to be as additional URL encoded parameter like in example:
GET /api/MT4/{tradePlatform}/UserRecordGet/{login}
Replace {
tradePlatform} and {login} with real identifiers.
Complete PowerShell example
# 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://cloud.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"