Add knowledge base sources in bulk
curl --request POST \
--url https://api.chatling.ai/v3/knowledge-base/sources/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent_id": "3132353852",
"sources": [
{
"type": "link",
"link": {
"url": "https://example.com/pricing"
}
},
{
"type": "link",
"link": {
"url": "https://example.com/shipping",
"auto_sync": "monthly"
}
},
{
"type": "faq",
"faq": {
"question": "Do you ship internationally?",
"answer": "Yes, to over **40 countries**."
}
}
]
}
'import requests
url = "https://api.chatling.ai/v3/knowledge-base/sources/batch"
payload = {
"agent_id": "3132353852",
"sources": [
{
"type": "link",
"link": { "url": "https://example.com/pricing" }
},
{
"type": "link",
"link": {
"url": "https://example.com/shipping",
"auto_sync": "monthly"
}
},
{
"type": "faq",
"faq": {
"question": "Do you ship internationally?",
"answer": "Yes, to over **40 countries**."
}
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: '3132353852',
sources: [
{type: 'link', link: {url: 'https://example.com/pricing'}},
{
type: 'link',
link: {url: 'https://example.com/shipping', auto_sync: 'monthly'}
},
{
type: 'faq',
faq: {
question: 'Do you ship internationally?',
answer: 'Yes, to over **40 countries**.'
}
}
]
})
};
fetch('https://api.chatling.ai/v3/knowledge-base/sources/batch', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.chatling.ai/v3/knowledge-base/sources/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3132353852',
'sources' => [
[
'type' => 'link',
'link' => [
'url' => 'https://example.com/pricing'
]
],
[
'type' => 'link',
'link' => [
'url' => 'https://example.com/shipping',
'auto_sync' => 'monthly'
]
],
[
'type' => 'faq',
'faq' => [
'question' => 'Do you ship internationally?',
'answer' => 'Yes, to over **40 countries**.'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.chatling.ai/v3/knowledge-base/sources/batch"
payload := strings.NewReader("{\n \"agent_id\": \"3132353852\",\n \"sources\": [\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/pricing\"\n }\n },\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/shipping\",\n \"auto_sync\": \"monthly\"\n }\n },\n {\n \"type\": \"faq\",\n \"faq\": {\n \"question\": \"Do you ship internationally?\",\n \"answer\": \"Yes, to over **40 countries**.\"\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.chatling.ai/v3/knowledge-base/sources/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"3132353852\",\n \"sources\": [\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/pricing\"\n }\n },\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/shipping\",\n \"auto_sync\": \"monthly\"\n }\n },\n {\n \"type\": \"faq\",\n \"faq\": {\n \"question\": \"Do you ship internationally?\",\n \"answer\": \"Yes, to over **40 countries**.\"\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chatling.ai/v3/knowledge-base/sources/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"3132353852\",\n \"sources\": [\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/pricing\"\n }\n },\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/shipping\",\n \"auto_sync\": \"monthly\"\n }\n },\n {\n \"type\": \"faq\",\n \"faq\": {\n \"question\": \"Do you ship internationally?\",\n \"answer\": \"Yes, to over **40 countries**.\"\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "knowledge_base_source",
"id": "0d1f6a3e-5b2c-4e8f-9a7d-3c6b1e2f4a5d",
"agent": {
"id": "3132353852",
"type": "ai_agent",
"name": "Support agent"
},
"type": "link",
"status": "pending",
"error": "<string>",
"characters": 123,
"resync_pending": true,
"last_synced_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"link": {
"url": "https://example.com/pricing",
"title": "Pricing",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"exclude_classes": [
"<string>"
],
"exclude_ids": [
"<string>"
],
"content": "# Pricing\n\nThe Pro plan is $20 a month."
},
"text": {
"preview": "<string>",
"content": "<string>"
},
"faq": {
"question": "Do you ship internationally?",
"answer": "Yes, to over **40 countries**."
},
"document": {
"filename": "Handbook.pdf",
"size": 482133,
"content_type": "application/pdf",
"content": "Employee handbook\n\n1. Working hours\nOur office is open 9 to 5."
},
"zoho": {
"title": "Returns policy",
"url": "https://support.example.com/hc/articles/360001",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "# Team handbook\n\nWelcome to the team."
},
"zendesk": {
"title": "Returns policy",
"url": "https://support.example.com/hc/articles/360001",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "# Team handbook\n\nWelcome to the team."
},
"notion": {
"title": "Returns policy",
"url": "https://support.example.com/hc/articles/360001",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "# Team handbook\n\nWelcome to the team."
},
"sharepoint": {
"filename": "Onboarding.docx",
"path": "/Shared Documents/HR",
"url": "https://example.sharepoint.com/sites/hr/Shared%20Documents/HR/Onboarding.docx",
"size": 58211,
"content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "Onboarding\n\nYour first week."
}
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is invalid or has been revoked.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "permission_error",
"code": "insufficient_permission",
"message": "This API key doesn't have create access to knowledge_base.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "not_found_error",
"code": "resource_not_found",
"message": "No agent with this ID exists, or this API key can't access it.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "invalid_request_error",
"code": "source_already_exists",
"message": "This agent's knowledge base already has this URL, as source 0d1f6a3e-5b2c-4e8f-9a7d-3c6b1e2f4a5d.",
"param": "sources.1.link.url",
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}Knowledge base
Add knowledge base sources in bulk
Adds up to 100 sources to an agent’s knowledge base. If any source is invalid, none are added. Validation errors list every problem, and other errors name the first invalid source in param, such as sources.2.link.url. Each source takes the same parameters as Add a knowledge base source, without agent_id.
POST
/
knowledge-base
/
sources
/
batch
Add knowledge base sources in bulk
curl --request POST \
--url https://api.chatling.ai/v3/knowledge-base/sources/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent_id": "3132353852",
"sources": [
{
"type": "link",
"link": {
"url": "https://example.com/pricing"
}
},
{
"type": "link",
"link": {
"url": "https://example.com/shipping",
"auto_sync": "monthly"
}
},
{
"type": "faq",
"faq": {
"question": "Do you ship internationally?",
"answer": "Yes, to over **40 countries**."
}
}
]
}
'import requests
url = "https://api.chatling.ai/v3/knowledge-base/sources/batch"
payload = {
"agent_id": "3132353852",
"sources": [
{
"type": "link",
"link": { "url": "https://example.com/pricing" }
},
{
"type": "link",
"link": {
"url": "https://example.com/shipping",
"auto_sync": "monthly"
}
},
{
"type": "faq",
"faq": {
"question": "Do you ship internationally?",
"answer": "Yes, to over **40 countries**."
}
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: '3132353852',
sources: [
{type: 'link', link: {url: 'https://example.com/pricing'}},
{
type: 'link',
link: {url: 'https://example.com/shipping', auto_sync: 'monthly'}
},
{
type: 'faq',
faq: {
question: 'Do you ship internationally?',
answer: 'Yes, to over **40 countries**.'
}
}
]
})
};
fetch('https://api.chatling.ai/v3/knowledge-base/sources/batch', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.chatling.ai/v3/knowledge-base/sources/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3132353852',
'sources' => [
[
'type' => 'link',
'link' => [
'url' => 'https://example.com/pricing'
]
],
[
'type' => 'link',
'link' => [
'url' => 'https://example.com/shipping',
'auto_sync' => 'monthly'
]
],
[
'type' => 'faq',
'faq' => [
'question' => 'Do you ship internationally?',
'answer' => 'Yes, to over **40 countries**.'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.chatling.ai/v3/knowledge-base/sources/batch"
payload := strings.NewReader("{\n \"agent_id\": \"3132353852\",\n \"sources\": [\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/pricing\"\n }\n },\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/shipping\",\n \"auto_sync\": \"monthly\"\n }\n },\n {\n \"type\": \"faq\",\n \"faq\": {\n \"question\": \"Do you ship internationally?\",\n \"answer\": \"Yes, to over **40 countries**.\"\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.chatling.ai/v3/knowledge-base/sources/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"3132353852\",\n \"sources\": [\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/pricing\"\n }\n },\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/shipping\",\n \"auto_sync\": \"monthly\"\n }\n },\n {\n \"type\": \"faq\",\n \"faq\": {\n \"question\": \"Do you ship internationally?\",\n \"answer\": \"Yes, to over **40 countries**.\"\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chatling.ai/v3/knowledge-base/sources/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"3132353852\",\n \"sources\": [\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/pricing\"\n }\n },\n {\n \"type\": \"link\",\n \"link\": {\n \"url\": \"https://example.com/shipping\",\n \"auto_sync\": \"monthly\"\n }\n },\n {\n \"type\": \"faq\",\n \"faq\": {\n \"question\": \"Do you ship internationally?\",\n \"answer\": \"Yes, to over **40 countries**.\"\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "knowledge_base_source",
"id": "0d1f6a3e-5b2c-4e8f-9a7d-3c6b1e2f4a5d",
"agent": {
"id": "3132353852",
"type": "ai_agent",
"name": "Support agent"
},
"type": "link",
"status": "pending",
"error": "<string>",
"characters": 123,
"resync_pending": true,
"last_synced_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"link": {
"url": "https://example.com/pricing",
"title": "Pricing",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"exclude_classes": [
"<string>"
],
"exclude_ids": [
"<string>"
],
"content": "# Pricing\n\nThe Pro plan is $20 a month."
},
"text": {
"preview": "<string>",
"content": "<string>"
},
"faq": {
"question": "Do you ship internationally?",
"answer": "Yes, to over **40 countries**."
},
"document": {
"filename": "Handbook.pdf",
"size": 482133,
"content_type": "application/pdf",
"content": "Employee handbook\n\n1. Working hours\nOur office is open 9 to 5."
},
"zoho": {
"title": "Returns policy",
"url": "https://support.example.com/hc/articles/360001",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "# Team handbook\n\nWelcome to the team."
},
"zendesk": {
"title": "Returns policy",
"url": "https://support.example.com/hc/articles/360001",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "# Team handbook\n\nWelcome to the team."
},
"notion": {
"title": "Returns policy",
"url": "https://support.example.com/hc/articles/360001",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "# Team handbook\n\nWelcome to the team."
},
"sharepoint": {
"filename": "Onboarding.docx",
"path": "/Shared Documents/HR",
"url": "https://example.sharepoint.com/sites/hr/Shared%20Documents/HR/Onboarding.docx",
"size": 58211,
"content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"auto_sync": "never",
"next_sync_at": "2023-11-07T05:31:56Z",
"content": "Onboarding\n\nYour first week."
}
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is invalid or has been revoked.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "permission_error",
"code": "insufficient_permission",
"message": "This API key doesn't have create access to knowledge_base.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "not_found_error",
"code": "resource_not_found",
"message": "No agent with this ID exists, or this API key can't access it.",
"param": null,
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "invalid_request_error",
"code": "source_already_exists",
"message": "This agent's knowledge base already has this URL, as source 0d1f6a3e-5b2c-4e8f-9a7d-3c6b1e2f4a5d.",
"param": "sources.1.link.url",
"request_id": "req_8Fq2kLm9TzX4vB7nC1dR5sYw"
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}{
"error": {
"type": "authentication_error",
"code": "validation_failed",
"message": "<string>",
"param": "<string>",
"request_id": "<string>",
"errors": [
{
"param": "<string>",
"message": "<string>"
}
]
}
}Headers
Body
application/json