MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now Learn More
Quotebut now the values come through as scientific notation,In Excel or Cognos?
Quote from: jackson.eyton on 16 Apr 2024 02:39:19 PMYou certainly can use the credentials method as specified for 11.2.4, ...
...(I'm forced to use powershell, please... someone help me...)...
function start-CognosSession {<#
.SYNOPSIS
Start a Cognos REST API session.
.DESCRIPTION
docs at http://<cognos_analytics_server>:<port>/api/api-docs
Asks for user name and password
Exits on empty password
.PARAMETER serverName
Cognos server to use.
.EXAMPLE
start-CognosSession "CognosServer.company.com"
#>
[CmdletBinding()]
param(
[parameter(position=0, mandatory=$true)]
[PSCustomObject]$serverName
)
# Write-Host "start-CognosSession start"
$CognosSession = [PSCustomObject]@{}
$protocol = "https"
$port = "9300"
$uriBase = "$protocol`://$serverName`:$port"
$contentType = "application/json; charset=utf-8"
$CognosSession | Add-Member -MemberType NoteProperty -Name 'protocol' -Value $protocol
$CognosSession | Add-Member -MemberType NoteProperty -Name 'serverName' -Value $serverName
$CognosSession | Add-Member -MemberType NoteProperty -Name 'port' -Value $port
$CognosSession | Add-Member -MemberType NoteProperty -Name 'uriBase' -Value $uriBase
$CognosSession | Add-Member -MemberType NoteProperty -Name 'contentType' -Value $contentType
$userNamespace = "MyNamespaceName"
$userName = Read-Host "User Name"
$UserPwd = Read-Host "Password" -AsSecureString
$err = $false
try {
$userPassword = ConvertFrom-SecureString -SecureString $UserPwd -AsPlainText
}
catch {
Write-Host "Empty password. Quitting."
$err = $true
}
if (!$err) {
$bdy = [PSCustomObject]@{}
$paramarray = @()
$param = [PSCustomObject]@{}
$param | Add-Member -MemberType NoteProperty -Name 'name' -Value "CAMNamespace"
$param | Add-Member -MemberType NoteProperty -Name 'value' -Value $userNamespace
$paramarray += $param
$param = [PSCustomObject]@{}
$param | Add-Member -MemberType NoteProperty -Name 'name' -Value "CAMUsername"
$param | Add-Member -MemberType NoteProperty -Name 'value' -Value $userName
$paramarray += $param
$param = [PSCustomObject]@{}
$param | Add-Member -MemberType NoteProperty -Name 'name' -Value "CAMPassword"
$param | Add-Member -MemberType NoteProperty -Name 'value' -Value $userPassword
$paramarray += $param
$bdy | Add-Member -MemberType NoteProperty -Name 'parameters' -Value $paramarray
$body = ConvertTo-Json $bdy
$uri = "$uriBase/api/v1/session"
$a = Invoke-RestMethod `
-Uri $uri `
-Method Put `
-contentType $contentType `
-SessionVariable "Session" `
-Body $body
# next line throws error, but retrieves a XSRF-Token cookie
Write-Host "Ignore the next error. The next line throws an error, but retrieves a XSRF-Token cookie."
$a = Invoke-RestMethod -Uri $uri -Method Get -contentType $contentType -WebSession $Session
$CognosSession | Add-Member -MemberType NoteProperty -Name 'Session' -Value $Session -TypeName 'Microsoft.PowerShell.Commands.WebRequestSession'
$Cookies = $Session.Cookies.GetCookies($uri)
$XSRFTOKEN = $Cookies["XSRF-TOKEN"].Value
[System.Collections.IDictionary]$headers = @{
'x-xsrf-token' = $XSRFTOKEN
'accept' = 'application/json'
'Cache-Control' = 'no-cache'
}
$CognosSession | Add-Member -MemberType NoteProperty -Name 'Headers' -Value $headers
$CognosSession
}
else {
$null
}
# Write-Host "start-CognosSession end"
}
function stop-CognosSession {<#
.SYNOPSIS
End a Cognos REST API session.
.DESCRIPTION
.PARAMETER CognosSession
CognosSession object created by start-CognosSession
.EXAMPLE
end-CognosSession -CognosSession $CognosSession
#>
[CmdletBinding()]
param(
[parameter(position=0, mandatory=$true)]
[PSCustomObject]$CognosSession
)
# Write-Host "stop-CognosSession start"
# log out
$uri = "$($CognosSession.uriBase)/api/v1/session"
Invoke-RestMethod -Uri $uri -Method Delete -WebSession $CognosSession.Session
# Write-Host "stop-CognosSession end"
}
$CognosSession = start-CognosSession -serverName $serverName
$uriBase = $CognosSession.uriBase
$protocol = $CognosSession.protocol
$serverName = $CognosSession.serverName
$port = $CognosSession.port
$Session = $CognosSession.Session
$headers = $CognosSession.Headers
$contentType = $CognosSession.contentType
$uri = "$uriBase/api/v1/content"
$content = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers -contentType $contentType -WebSession $Session
$content.content | Format-List
stop-CognosSession -CognosSession $CognosSession
$uriBase/api/v1/users?identifier=$namespace&top=$top&skip=$skip
$uriBase/api/v1/namespace_folder/$namespace/items?limit=$limit&offset=$offset
...to limit my call to something of a reasonable size that should return in a reasonable time.Quote from: patternghost on 27 May 2021 09:56:54 AMAfter trial and error, I found that if I send /users?identifier=<namespace> will return all users in the namespace. I can work with that.
BSP Software Documentation |
MetaManager Documentation and Knowledgebase |
Version Control Documentation and Knowledgebase |
BSP Software | Resources | About Us | ||
MetaManager | BSP Software Training | BSP Software | ||
Integrated Control Suite | YouTube Channel | Micro Strategies Inc | ||
Security Migration | IBM Cognos | |||
Integrated Management Suite | ||||