Tuesday, November 19, 2019

Calling ION APIs from Powershell

Further to the post on how to call ION APIs from Postman, here are quick notes on how to call ION APIs from Powershell:

In the last post we had a json file from ION API with the credentials information:

{
"ti":"######_TRN",
"cn":"Example_TRN",
"dt":"12",
"ci":"######_TRN~********************",
"cs":"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"iu":"https://mingle-ionapi.se2.inforcloudsuite.com",
"pu":"https://mingle-sso.se2.inforcloudsuite.com:443/######_TRN/as/",
"oa":"authorization.oauth2",
"ot":"token.oauth2",
"or":"revoke_token.oauth2",
"ev":"^^^^^^^^^^^^",
"v":"1.0",
"saak":"######_TRN$$$$$$$$$$$$$$$$$$$",
"sask":":::::::::::::::::::::::::::::"

}

And a URI:

https://mingle-ionapi.se2.inforcloudsuite.com/#######_TRN/M3/m3api-rest/execute/EXPORTMI/Select/?SEPC=%7C&HDRS=1&QERY=count(*)%20from%20MITTRA
We can use this information to call the ION API from Powershell:

#Set the URI

$Uri = "https://mingle-sso.se2.inforcloudsuite.com:443/####_TRN/as/token.oauth2"

Set the token request:

$Body = @{
grant_type = 'password'
username = '######_TRN$$$$$$$$$$$$$$$$$$$'
password = ':::::::::::::::::::::::::::::'
client_id = '######_TRN~********************'
client_secret = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
scope = ''
redirect_uri = 'https://localhost/'
}

Request the token from ION API:

$AuthResult = Invoke-RestMethod -Method Post -Uri $Uri -Body $Body

We can show the token in Powershell:

$AuthResult.access_token

We then call the API, passing in the URI and the token:

$output = Invoke-RestMethod -Uri 'https://mingle-ionapi.se2.inforcloudsuite.com/#######_TRN/M3/m3api-rest/execute/EXPORTMI/Select/?SEPC=%7C&HDRS=1&QERY=count(*)%20from%20MITTRA' -Headers @{ 'Authorization' = 'Bearer TokenValue' }

Get the result of the API call - in this case the number of records in MITTRA

$output.miResult.MIRecord.NameValue.Value

In Powershell this is:

Giving us a row count for MITTRA of 4,152,575 rows.

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete