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.

Get and search for articles and categories

You can get the root category for the Knowledge Base.

let kb = Kustomer.kbProvider
kb.getRootCategory(lang: "en_us", knowledgeBaseID: nil) { result in
  switch result {
  case .success(let rootCategory):
    print("Root category: \(rootCategory)")
  case .failure(let error):
    print("Error fetching root category! - \(error)")
  }
}

Get and search for articles and categories

Get a category

You can get a category based on the category ID:

kb.getCategory(by: "CategoryID", childrenLimit: 100, lang: "en_us", knowledgeBaseID: nil) { result in
  switch result {
  case .success(let response):
    let category = response.data
    let subcategories = response.subCategories
    let articles = response.articles
    print("Got category: \(category) with sub categories: \(subcategories) and articles: \(articles)")
  case .failure(let error):
    print("Error fetching category! - \(error)")
  }
}

Get an article

You can get an article based on the article ID:

kb.getArticle(by: "ArticleID", lang: "en_us", knowledgeBaseID: nil) { result in
  switch result {
  case .success(let article):
    print("Got article: \(article)")
  case .failure(let error):
    print("Error fetching article! - \(error)")
  }
}

Search articles

You can search for articles based on a string parameter:

kb.searchArticles(term: "forgot password", page: 1, pageSize: 100, lang: "en_us") { result in
  switch result {
  case .success(let articles):
    print("Relevant articles: \(articles)")
  case .failure(let error):
    print("Error searching articles! - \(error)")
  }
}

Extended Knowledge Base article properties and category properties

These properties are Deprecated & not supported.

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.

Get all categories in the root with KBProvider

This method is Deprecated & not supported.

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

This method is Deprecated & not supported.

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?