从 PowerShell 使用 Cogos Analytics REST API

问题描述 投票:0回答:1

使用 Cognos Analytics 11.2.4
尝试编写 PowerShell 脚本来通过 Cognos Analytics REST API 管理 Cognos Analytics。我的第一次尝试是创建一个新会话(登录)。到目前为止我还一事无成。

以下文档和帮助可在以下位置找到:
IBM Cognos Analytics REST API(及相关)
https://我的服务器名称:9300/api/api-docs/
PowerShell 调用-RestMethod
使用 TeamCity REST API 更新值时不支持的媒体类型

每当我尝试此操作时,我都会收到错误:

Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.

服务器上的本地 API 文档不包含 415 作为可能的响应。 (...无论如何这都没有帮助,因为文档不包含文档中的错误响应的任何可能的因果关系。)

我怎样才能克服这个困难?我真的可以在正确的方向上轻轻推动。

这是我尝试过的代码。以前的尝试已包含并注释掉。

#  docs at
#  http://<cognos_analytics_server>:<port>/api/api-docs

$serverName = "<cognos_analytics_server>"
$port = "<port>"
$userNamespace = "<external_directory_namespace>"
$userName = Read-Host "User Name:  "

$pwd = Read-Host "Password" -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
$userPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
# then free up the unmanged memory afterwards
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)

#  Attempt 1
#$p = @()
#$p += @{
#      name = "CAMNamespace"
#      value = $userNamespace
#    }
#$p += @{
#      name = "CAMUsername"
#      value = $userName
#    }
#$p += @{
#      name = "CAMPassword"
#      value = $userPassword
#    }
#
#$body = @{
#  parameters = $p
#}

#  Attempt 2
#$body = '{
#  "parameters": [
#    {
#      "name": "CAMNamespace",
#      "value": "' + $userNamespace + '"
#    },
#    {
#      "name": "CAMUsername",
#      "value": "' + $userName + '"
#    },
#    {
#      "name": "CAMPassword",
#      "value": "' + $userPassword + '"
#    }
#  ]
#}'

#  Attempt 3
#$body = '{"parameters": [{"name": "CAMNamespace","value": "' + $userNamespace + '"},{"name": "CAMUsername","value": "' + $userName + '"},{"name": "CAMPassword","value": "' + $userPassword + '"}]}'

#  Attempt 4
#$body = "{`"parameters`": [{`"name`": `"CAMNamespace`",`"value`": `"$userNamespace`"},{`"name`": `"CAMUsername`",`"value`": `"$userName`"},{`"name`": `"CAMPassword`",`"value`": `"$userPassword`"}]}"

#  Attempt 5
$body = "{
  `"parameters`": [
    {
      `"name`": `"CAMNamespace`",
      `"value`": `"$userNamespace`"
    },
    {
      `"name`": `"CAMUsername`",
      `"value`": `"$userName`"
    },
    {
      `"name`": `"CAMPassword`",
      `"value`": `"$userPassword`"
    }
  ]
}"


$uri = "$protocol`://$serverName`:$port/api/v1/session"

#  Attempt 1
#Invoke-RestMethod -Uri $uri -Method Put -Body $body

#  Further attempts
Invoke-RestMethod -contentType "text/plain" -Uri $uri -Method Put -Body $body
powershell rest cognos cognos-bi cognos-11
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.