Update Cireson Knowledge Article using API
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
-
Justin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭@Michael_Canan
I've attached a script based on what you started with here. I think it accomplishes what you're after.
5
Answers
I've attached a script based on what you started with here. I think it accomplishes what you're after.