We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Publishing articles through an API

mhashemi
Mega Sage

I am looking for a way to either create articles in a "published" state, or trigger the "publish" workflow through the REST API.

 

I wrote a little PowerShell snippet that is creating the articles in "draft":

 

 

 

$serviceNowCredential = Get-Credential
$uri = "https://<instance>.service-now.com/api/now/table/kb_knowledge"
$method = "POST"

# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ServiceNowCredential.UserName, $serviceNowCredential.GetNetworkCredential().Password)))

# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization', ('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept', 'application/json')
$headers.Add('content-type', 'application/json')

$tempObj = [PsCustomObject]@{
    text              = 'Some stuff goes here' 
    sys_created_by    = 'user@emaildomain.com'
    author            = 'e9326af747d9611091271c42846d43bd'
    active            = 'true'
    kb_knowledge_base = 'cf33206447e5a11091271c42846d43ac'
    topic             = 'General'
    short_description = 'How to do a Thing'
    article_type      = 'text'
    kb_category       = 'a196b8a44729a11091271c42846d438c'
}

$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body ($tempObj | ConvertTo-Json) -ErrorAction Stop

 

 

 That works just fine, but I don't see any way to publish the resulting article. I found How to create knowledge article in ServiceNow with article state as Publish?, but the answer just says, "go look at the REST API Explorer".

 

I did that, which made me think to try a PUT with "scheduled_publish_date", then "published" with today's date (2023-03-14), but neither helped. Is there another field, at which I should be looking? What am I missing?

1 ACCEPTED SOLUTION

mhashemi
Mega Sage

In the end, I'm sticking with the script to create the article, but then created a business rule to automatically kick of the approval workflow any time the API service account does an insert.

View solution in original post

1 REPLY 1

mhashemi
Mega Sage

In the end, I'm sticking with the script to create the article, but then created a business rule to automatically kick of the approval workflow any time the API service account does an insert.