Create KB article via ServiceNow Table API

590 Views Asked by At

We're trying to create ServiceNow KB article using ServiceNow Table API

url = 'https://devXXXX.service-now.com/api/now/table/kb_knowledge'

Currently we're passing html content data (with tags) in ‘text’ field and able to create KB article

[..]

response = requests.post(url, auth=(user, password), headers=headers, data="{\"active\":\"True\",\"valid_to\":\"01-01-2100\",\"short_description\":\"KB Article\",\"text\":\"<h1> Example Article </h1> <p>Testing</p>}")

[..]

Instead of passing the html content in ‘text’ field, we're trying options to read the entire html file or any file content and create KB article in ServiceNow

Any suggestions please..

2

There are 2 best solutions below

0
On

Instead of posting the actual html in the data field, maybe you could just put the URL to actual page, but store the actual page elsewhere.

0
On

From the docs section Table - POST /now/table/{tableName} it seems like what you might be looking for is the "data" option - it allows you to put any type of text/XML into the article.

# Example 1 Python XML
response = requests.post(url, 
     auth=(user, pwd), 
     headers=headers, 
     data="""<request><entry>
          <short_description>Unable to connect to office wifi</short_description>
          <assignment_group>
               287ebd7da9fe198100f92cc8d1d2154e
          </assignment_group>
          <urgency>2</urgency>
          <impact>2</impact>
     </entry></request>"""
     )

# Example 2 CURL - JSON
curl "https://instance.servicenow.com/api/now/table/incident" \
--request POST \
--header "Accept:application/json" \
--header "Content-Type:application/json" \
--data "{'short_description':'Unable to connect to office wifi','assignment_group':'287ebd7da9fe198100f92cc8d1d2154e','urgency':'2','impact':'2'}" \
--user 'username':'password'

If you want to use HTML it seems you'll have to stick with text for that case, as it doesn't seem like they are using "text" option for anything in their Tables API (might be the case that you're using a deprecated API option for that so be careful)