I was wondering where I could find example code to use the TM1 REST API using PowerShell ?
I did my own research first. I can use Postman to execute statements.
Postman can deliver the code that you can use in other programming languages, but PowerShell is not part of the supported languages.
Using general REST API codes in PowerShell I was able to at least do something, also using this link:
https://www.ibm.com/developerworks/comm ... bb14&ps=50 (see the code by Bob Milli)
but in general I still can't get it working. Does anyone have example code, for example to get a list of cubes ?
Authentication is Basic, just TM1 authentication.
For example, this sort of works (no errors in PowerShell ISE):
Code: Select all
$AdminHost= "AEX199"
$httpport = "8001"
$TM1User = "wim"
$userresponse = Read-host "Input the password?" -AsSecureString
$TM1Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($userresponse))
$headers = @{"Authorization" = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($TM1User):$($TM1Password)"));}
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$TM1_Instance_url = 'http://' + $Adminhost + ':' + $httpport + '/api/v1/Cubes'
$TM1cubes = Invoke-RestMethod -Method Get -uri $TM1_Instance_url -WebSession $session -Headers $headers
$TM1cubes | Out-File c:\debug.txt
The output in the text file is only very little:
Code: Select all
@odata.context value
-------------- -----
$metadata#Cubes {@{@odata.etag=W/"8c2097d4083b864dcfec672c9536c919e660a898"; Name=Aexis_Planning; Rules=; DrillthroughRules=[] = S: 'Z_Drill detail (Aexis_Planning)';...
Wim