Manage Knowledge Center Content in the API
Bulk operations for your knowledge center content using the API
Overview
Before You BeginThis article covers bulk operations for managing your Knowledge Center content via the API. If you're looking for help with managing your Knowledge Center content in the UI, click here.
While all Knowledge Center management operations are available in the UI, it is often more convenient to manage your content programmatically via scripted API calls.
Using the API to manage your Knowledge Center is useful when, for example, you would like to make changes to an entire category at once or manage a built-in category that cannot be deleted.
This article covers the Knowledge Center management operations available via the API and walks you through how to make bulk changes to your content using the available endpoints.
Prerequisites
Note:The Knowledge Center is an AI feature. If you don't see the Knowledge Center under Settings → Chatbot and AI → AI chatbot → Knowledge Center, reach out to your implementation partner or Glassix contact for more information about getting AI features switched on.
Before you start managing your Knowledge Center via the API, you should make sure you have the following:
- A way to make API calls outside of the developer documentation, and a basic understanding of the Knowledge Center API.
- A way to run scripts and a basic understanding of a scripting language like JavaScript or Python.
- An API access token to provide in the request headers.
- Knowledge Center access.
If you don't already have a way to make API calls outside of the developer documentation, we recommend downloading a tool like Postman.
Bulk Operations and Examples
Important:Most bulk operations are not possible using the Try It tools in the developer documentation. You will need a tool like Postman for the examples in this guide.
After reviewing and confirming you have met all of the prerequisites above, you can use any of the methods below to manage your Knowledge Center content in bulk:
Bulk Update Content
Bulk updating Knowledge Center content via the API is a three-step process:
- Get a list of your category IDs using the Get All Content Categories endpoint
- Get a list of your content IDs in each category using the Get All Contents endpoint
- Loop through each content ID and update your content using the Update Content endpoint
After each step, unless you plan to update all your Knowledge Center content, you will need to process the data returned by the API. As a basic example, after getting a list of category IDs, you will likely want to choose a specific category to edit before proceeding with step 2.
In addition, because the Update Content endpoint requires you to provide a title and text for each piece of content, you will likely want to pass these values through from the Get All Contents endpoint if you're just updating access or the category.
Example
In this example, we will move all content from one category to another, preserving each item's existing title and text.
Step 1: Get the category IDs
curl --request GET \
--url 'https://api.glassix.com/v1.2/knowledge/categories' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Accept: application/json'const response = await fetch('https://api.glassix.com/v1.2/knowledge/categories', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Accept': 'application/json'
}
});
const categories = await response.json();
console.log(categories);import requests
url = 'https://api.glassix.com/v1.2/knowledge/categories'
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Accept': 'application/json'
}
response = requests.get(url, headers=headers)
categories = response.json()
print(categories)Note the IDs of the source category (where content currently lives) and the destination category (where you want to move it).
Step 2: Get the content in the source category
const SOURCE_CATEGORY_ID = 'source-category-id';
const TOKEN = 'YOUR_ACCESS_TOKEN';
async function getCategoryContent(categoryId) {
const allContent = [];
let page = 1;
while (true) {
const response = await fetch(
`https://api.glassix.com/v1.2/knowledge/categories/${categoryId}/contents?page=${page}`,
{
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Accept': 'application/json'
}
}
);
const data = await response.json();
if (!data.items || data.items.length === 0) break;
allContent.push(...data.items);
if (!data.hasNextPage) break;
page++;
}
return allContent;
}
const items = await getCategoryContent(SOURCE_CATEGORY_ID);import requests
SOURCE_CATEGORY_ID = 'source-category-id'
TOKEN = 'YOUR_ACCESS_TOKEN'
def get_category_content(category_id):
all_content = []
page = 1
while True:
url = f'https://api.glassix.com/v1.2/knowledge/categories/{category_id}/contents'
response = requests.get(
url,
headers={
'Authorization': f'Bearer {TOKEN}',
'Accept': 'application/json'
},
params={'page': page}
)
data = response.json()
items = data.get('items', [])
if not items:
break
all_content.extend(items)
if not data.get('hasNextPage'):
break
page += 1
return all_content
items = get_category_content(SOURCE_CATEGORY_ID)Step 3: Update each item to the new category
const DESTINATION_CATEGORY_ID = 'destination-category-id';
async function updateContent(item) {
const response = await fetch(
`https://api.glassix.com/v1.2/knowledge/contents/${item.id}`,
{
method: 'PUT',
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: item.title,
text: item.text,
categoryId: DESTINATION_CATEGORY_ID
})
}
);
return response.json();
}
for (const item of items) {
await updateContent(item);
console.log(`Updated: ${item.title}`);
await new Promise(resolve => setTimeout(resolve, 200));
}import time
DESTINATION_CATEGORY_ID = 'destination-category-id'
def update_content(item):
url = f"https://api.glassix.com/v1.2/knowledge/contents/{item['id']}"
response = requests.put(
url,
headers={
'Authorization': f'Bearer {TOKEN}',
'Content-Type': 'application/json'
},
json={
'title': item['title'],
'text': item['text'],
'categoryId': DESTINATION_CATEGORY_ID
}
)
return response.json()
for item in items:
update_content(item)
print(f"Updated: {item['title']}")
time.sleep(0.2)Bulk Delete Content
Tip:If you want to delete all the content in a custom category (any category other than General, Conversation History or Canned Replies), you can delete the category itself in the UI and its contents will be removed.
Bulk deleting Knowledge Center content via the API is a three-step process:
- Get a list of your category IDs using the Get All Content Categories endpoint
- Get a list of your content IDs in each category using the Get All Contents endpoint
- Loop through each content ID and delete your content using the Delete Content endpoint
After each step, unless you plan to delete all your Knowledge Center content, you will need to process the data returned by the API. As a basic example, after getting a list of category IDs, you will likely want to choose a specific category to delete before proceeding with step 2.
Example
In this example, we will delete all content from a single category while keeping the category itself.
Step 1: Get the category ID
Use the Get All Content Categories request from the Bulk Update example above to find the ID of the category you want to clear.
Step 2: Get the content IDs in that category
Use the Get All Contents request from the Bulk Update example above, substituting your target category ID.
Step 3: Delete each item
curl --request DELETE \
--url 'https://api.glassix.com/v1.2/knowledge/contents/CONTENT_ID' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'const TOKEN = 'YOUR_ACCESS_TOKEN';
async function deleteContent(contentId) {
const response = await fetch(
`https://api.glassix.com/v1.2/knowledge/contents/${contentId}`,
{
method: 'DELETE',
headers: {
'Authorization': `Bearer ${TOKEN}`
}
}
);
return response.ok;
}
for (const item of items) {
const success = await deleteContent(item.id);
console.log(`${success ? 'Deleted' : 'Failed'}: ${item.title}`);
await new Promise(resolve => setTimeout(resolve, 200));
}import requests
import time
TOKEN = 'YOUR_ACCESS_TOKEN'
def delete_content(content_id):
url = f'https://api.glassix.com/v1.2/knowledge/contents/{content_id}'
response = requests.delete(
url,
headers={'Authorization': f'Bearer {TOKEN}'}
)
return response.ok
for item in items:
success = delete_content(item['id'])
status = 'Deleted' if success else 'Failed'
print(f"{status}: {item['title']}")
time.sleep(0.2)Bulk Export Content
Bulk exporting Knowledge Center content via the API is a two-step process:
- Get a list of your category IDs using the Get All Content Categories endpoint
- Loop through each category ID and pull its content using the Get All Contents endpoint
The Get All Contents endpoint is paginated, so for categories with a large amount of content, you will need to make multiple requests to retrieve everything.
Tip:Category IDs are not visible in the UI. The Get All Content Categories endpoint is the only way to retrieve them, so you'll need to run it at least once before exporting.
Example
In this example, we will export all content from a single category and save the results to a file.
Step 1: Get the category ID
curl --request GET \
--url 'https://api.glassix.com/v1.2/knowledge/categories' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Accept: application/json'const response = await fetch('https://api.glassix.com/v1.2/knowledge/categories', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Accept': 'application/json'
}
});
const categories = await response.json();
console.log(categories);import requests
url = 'https://api.glassix.com/v1.2/knowledge/categories'
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Accept': 'application/json'
}
response = requests.get(url, headers=headers)
categories = response.json()
print(categories)Note the ID of the category you want to export.
Step 2: Export all content from the category
Loop through the paginated results, collecting every item.
const CATEGORY_ID = 'your-category-id';
const TOKEN = 'YOUR_ACCESS_TOKEN';
async function exportCategory(categoryId) {
const allContent = [];
let page = 1;
while (true) {
const response = await fetch(
`https://api.glassix.com/v1.2/knowledge/categories/${categoryId}/contents?page=${page}`,
{
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Accept': 'application/json'
}
}
);
const data = await response.json();
if (!data.items || data.items.length === 0) break;
allContent.push(...data.items);
if (!data.hasNextPage) break;
page++;
}
return allContent;
}
const content = await exportCategory(CATEGORY_ID);
console.log(`Exported ${content.length} items`);
// Save to a file in Node.js
import { writeFileSync } from 'fs';
writeFileSync('export.json', JSON.stringify(content, null, 2));import requests
import json
CATEGORY_ID = 'your-category-id'
TOKEN = 'YOUR_ACCESS_TOKEN'
def export_category(category_id):
all_content = []
page = 1
while True:
url = f'https://api.glassix.com/v1.2/knowledge/categories/{category_id}/contents'
response = requests.get(
url,
headers={
'Authorization': f'Bearer {TOKEN}',
'Accept': 'application/json'
},
params={'page': page}
)
data = response.json()
items = data.get('items', [])
if not items:
break
all_content.extend(items)
if not data.get('hasNextPage'):
break
page += 1
return all_content
content = export_category(CATEGORY_ID)
with open('export.json', 'w') as f:
json.dump(content, f, indent=2)
print(f'Exported {len(content)} items to export.json')To export every category, wrap the loop above in an outer loop over the category list returned in Step 1.
Bulk Create Content
Note:The Create Content endpoint only supports creating snippets (plain text content). You cannot start a website scan or upload a file via the API, these content types must be created in the UI.
Bulk creating Knowledge Center content via the API is a two-step process:
- Get a list of your category IDs using the Get All Content Categories endpoint to identify where your new content should go
- Loop through your snippets and create each one using the Create Content endpoint
Because Create Content is not a bulk endpoint, you'll need to call it once per snippet. If you have a large number of snippets to create, consider adding a short delay between requests to avoid hitting rate limits.
Example
In this example, we will create several snippets in a target category from a local list.
Step 1: Get the category ID
Use the Get All Content Categories request from the Bulk Update example above to find the ID of the category you want to create content in.
Step 2: Create the snippets in a loop
curl --request POST \
--url 'https://api.glassix.com/v1.2/knowledge/contents' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"categoryId": "your-category-id",
"title": "Return policy",
"text": "Customers can return any item within 30 days of purchase."
}'const CATEGORY_ID = 'your-category-id';
const TOKEN = 'YOUR_ACCESS_TOKEN';
const snippets = [
{ title: 'Return policy', text: 'Customers can return any item within 30 days of purchase.' },
{ title: 'Shipping times', text: 'Standard shipping takes 3-5 business days.' },
{ title: 'Contact hours', text: 'Our support team is available Monday-Friday, 9am-5pm.' }
];
async function createSnippet(snippet) {
const response = await fetch('https://api.glassix.com/v1.2/knowledge/contents', {
method: 'POST',
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
categoryId: CATEGORY_ID,
title: snippet.title,
text: snippet.text
})
});
return response.json();
}
for (const snippet of snippets) {
const result = await createSnippet(snippet);
console.log(`Created: ${result.title}`);
await new Promise(resolve => setTimeout(resolve, 200));
}import requests
import time
CATEGORY_ID = 'your-category-id'
TOKEN = 'YOUR_ACCESS_TOKEN'
snippets = [
{'title': 'Return policy', 'text': 'Customers can return any item within 30 days of purchase.'},
{'title': 'Shipping times', 'text': 'Standard shipping takes 3-5 business days.'},
{'title': 'Contact hours', 'text': 'Our support team is available Monday-Friday, 9am-5pm.'}
]
def create_snippet(snippet):
url = 'https://api.glassix.com/v1.2/knowledge/contents'
response = requests.post(
url,
headers={
'Authorization': f'Bearer {TOKEN}',
'Content-Type': 'application/json'
},
json={
'categoryId': CATEGORY_ID,
'title': snippet['title'],
'text': snippet['text']
}
)
return response.json()
for snippet in snippets:
result = create_snippet(snippet)
print(f"Created: {result.get('title')}")
time.sleep(0.2)You can adapt this pattern to read snippets from a CSV, a JSON file, or any other source, just replace the in-line.snippets array with your own data.