Knowledge Base API
We're trying to get KB articles with API calls.
Here is our Powershell-Script:
---
param ($Data1,
$Data2,
$Data3,
$Data4,
$Data5,
$Data6,
$Data7)
#enter your portal URL here
$site = "https://portal.xxxxx.xx"
$credentials = @{
UserName = 'DOMAIN\username'
Password = 'password'
LanguageCode = 'ENU'
}
$jsonCredentials = $credentials | ConvertTo-Json
#first retrieve your access token
$url = $site + "/api/V3/Authorization/GetToken"
$apiKey = try { Invoke-RestMethod $url -Method POST -Body $jsonCredentials -ContentType 'application/json' } catch { $_.Exception.Response }
$authVal = "Token " + $apiKey
$Data5 = 76
$url1 = $site + "/api/V3/KnowledgeBase/GetKnowledgeArticle?articleId={$Data5}"
#$url1 = $site + "/api/V3/User/GetUserList" --> diese Abfrage funktioniert.
$response1 = try { Invoke-RestMethod $url1 -Method GET -ContentType 'application/json' -Headers @{ "AUTHORIZATION" = $authVal } }
catch { $_.Exception.Response }
---
We're not able to get a result with this script. Could someone help us?
Thanks,
Raffael
Best Answer
-
Geoff_Ross Cireson Consultant O.G.Hi Raffael,
You don'ty need the {} in the API call. That's in the documentation to indicate a placeholder token.
Also, below is a slightly different API endpoint that might give desired results:$url1 = $site + "/api/V3/Article/Get?articleId=$Data5"
See how that works?
Geoff5
Answers
You don'ty need the {} in the API call. That's in the documentation to indicate a placeholder token.
Also, below is a slightly different API endpoint that might give desired results:
See how that works?
Geoff
Based on help from Cireson Support (this was one step to the solution) and based on your help, my colleague was able to resolve the problem.
This is the working Powershell-Script:
---
param ($Data1,
$Data2,
$Data3,
$Data4,
$Data5,
$Data6,
$Data7)
#enter your portal URL here
$site = "https://portal.xxxxx.xx"
$credentials = @{
UserName = 'DOMAIN\username'
Password = 'password'
LanguageCode = 'ENU'
}
$jsonCredentials = $credentials | ConvertTo-Json
#first retrieve your access token
$url = $site + "/api/V3/Authorization/GetToken"
$apiKey = try { Invoke-RestMethod $url -Method POST -Body $jsonCredentials -ContentType 'application/json' } catch { $_.Exception.Response }
$authVal = "Token " + $apiKey
$Data5 =1
$url1 = $site + "/api/V3/KnowledgeBase/GetHTMLKnowledgeArticle?knowledgeArticleId=$Data5"
#$url1 = $site + "/api/V3/User/GetUserList"
$response1 = try { Invoke-RestMethod $url1 -Method GET -ContentType 'application/json' -Headers @{ "AUTHORIZATION" = $authVal } }
catch { $_.Exception.Response }
$Data1 = "test"
---
Thanks for your help!
Take care,
Raffael