Work with the Knowledge Base

Learn how to work with the Knowledge Base with the Kustomer Core SDK.

You can build your own chat UI to work with the Knowledge Base articles, categories, and more.

Knowledge Base data storage management

Populate Knowledge Base data

This method is Deprecated & not supported.
You can manually populate Knowledge Base data.

kb.update({ result in
        switch result {
          case .success:
            kprint("updated. lastUpdateAt is now \(kb.lastUpdateAt)")
          case .failure(let error):
            kprint(error.localizedDescription)
        }
      })

Clear Knowledge Base data

This method is Deprecated & not supported.
You can manually clear Knowledge Base data.

kb.clearLocalDataStore()

Request information on Knowledge Base data

These methods are Deprecated & not supported.
You can request information about the local data store.

kb.hasNeverUpdated
kb.lastUpdateAt

Update the Knowledge Base data store

Get and search for articles and categories

Deprecated. Use getRootCategory instead.
You can get articles and categories for the root of the Knowledge Base.

let kb = KBProvider.shared
      kb.getEntriesForRoot(completion: { r in
      switch r {
      case .success(let items):
        let one = items.first
            dump(items)
          case .failure(let error):
            dump(error)
        }
      })

Get and search for articles and categories

You can get root category of the Knowledge Base.

let kb = KBProvider.shared
      kb.getRootCategory(lang: String, knowledgeBaseId: String?, completion: { r in
      switch r {
      case .success(let items):
        let one = items.first
            dump(items)
          case .failure(let error):
            dump(error)
        }
      })

Get an article or category

You can get an an article based on the article ID:

kb.getArticle(id: String, completion: { r in
        switch r {
          case .success(let article):
            kdump(article)
          case .failure(let error):
            kdump(error)
        }
      })

You can get a category based on the category ID:

kb.getCategory(id: String, completion: { r in
        switch r {
          case .success(let category):
            kdump(category)
          case .failure(let error):
            kdump(error)
        }
      })

Get by parent category ID

You can get articles and categories based on the parent categoryId, and then get all child articles and categories.

kb.getArticlesAndCategories(parentCategoryId: String, completion: •)

Search by text

You can search for articles and categories based on the searchText:

kb.getArticlesAndCategories(searchText: String, completion: •)

Extended Knowledge Base article properties and category properties

You can use the completeObject() method on KUSKBCategory and KUSKBArticle objects to access extended attributes for articles and categories. While the rawJSON property is the same, the method does not parse the rawJSON property into a dictionary.

To view extended article properties, see KUSKBArticle.

To view extended category properties, see KUSKBCategory.

category.completeObject()

Update from the Kustomer API

To force an update from the Kustomer REST API, use [update(_:)](ref:update_) .

To learn more, see KBProvider.

Get all categories in the root with KBProvider

To get all the categories in the root category, use KBProvider.shared.getEntriesForRoot(completion: { r in:

KBProvider.shared.getEntriesForRoot(completion: { r in
      switch r {
      case .success(let items):
        let one = items.first
        if one is KUSKBArticle {
          let article = one as! KUSKBArticle
          
          KBProvider.shared.getArticle(id: article.id!, completion: { r in
            switch r {
            case .success(let article):
              print(article.htmlBody)
            case .failure(let erro):
              print(erro.localizedDescription)
            }
          })
        } else if one is KUSKBCategory {
          
          if one is KUSKBCategory {
            let category = one as! KUSKBCategory
            
            KBProvider.shared.getCategory(id: category.id!, completion: { r in
              switch r {
              case .success(let article):
                print(category.title)
              case .failure(let erro):
                print(erro.localizedDescription)
              }
            })
          }
        }
      case .failure(let err):
        print(err.localizedDescription)
      }
    })

To learn more, see KBProvider.

Get articles and categories with KUSKBCategory

To get all the child articles and categories for a given KUSKBCategory, use KBProvider.shared.KBProvider.shared.getEntries(categoryId: "foo", search: "hello", completion: ....

To learn more, see KBProvider.


Did this page help you?