Home Analyst Portal

Update Cireson Knowledge Article using API

Michael_CananMichael_Canan Customer IT Monkey ✭
I am trying to go through and add Keywords to all of my Knowledge Articles using the api/V3/KnowledgeBase/AddOrUpdateHTMLKnowledgeApi

The first issue I am running into is trying to grab all the Knowledge articles in Cireson, as of now I am only able to get them if I know the ID.

Second issue is trying to POST the new data, I keep getting Internal Server Error.

Here is my code I am using

#enter your portal URL here$site = "https://myportal.com"
$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
$id =2
$url1 = $site + "/api/V3/KnowledgeBase/GetHTMLKnowledgeArticle?knowledgeArticleId=$id
$response1 = try { Invoke-RestMethod $url1 -Method GET -ContentType 'application/json' -Headers @{ "AUTHORIZATION" = $authVal } }     catch { $_.Exception.Response }

#Take the title of the Article and create keywords based off of it for better search results
#ex. Server -> Ser Serv Serve Server$keywords = ""$title = $response1.Title$title = $title.split(" ")foreach($word in $title){        if($word.Length -gt 4)        {            $length=$word.Length            while($length - 2 -gt 0)            {                $keywords += $word.substring(0,$length--) + " "                            }        }
}#create a new article that will update old one$newArticle = $response1$newArticle.Keywords = $keywords$newArticle = ConvertTo-Json $newArticle$oldArticle = ConvertTo-Json $response1#everything above this works so far

$body=@{ formJson" : { "isDirty: "True", "current" : { $newArticle }, "original" : { $oldArticle } } }"@$url2 = $site + "/api/V3/KnowledgeBase/AddOrUpdateHTMLKnowledgeApi"$apiKey = try { Invoke-RestMethod $url -Method POST -Body $jsonCredentials -ContentType 'application/json' } catch { $_.Exception.Response }
$authVal = "Token " + $apiKey$response2 = try { Invoke-RestMethod $url2 -Method Post -Body $body -ContentType 'application/json; charset=utf-8' -Headers @{ "AUTHORIZATION" = $authVal } }     catch { $_.Exception.Response }

Best Answer

Answers

Sign In or Register to comment.