Thank you for taking the time to answer and post these great tips and examples. I saw a similar tip in another post but didn’t quite understand it. With your examples, I now understand where to look in the browser’s network output.
I’ve now got my source KB export working, including most of the category titles. As expected, I need to access object {KnowledgeBaseCategoryTranslation} with the translation_id of the category_id. I get that object with the API endpoint: /api/v1/knowledge_bases/[KB_ID]/answers/[ANSWER_ID]
My missing translated category titles are a result of my script’s logic: if a category doesn’t have a direct answer but a subcategory, the answer_ids array is empty and therefore skips my logic to get the translation in the answer. Since this isn’t a big problem in my specific case for five categories, I manually add the translated category titles to my export file.
If you ever need to do something similar, drop me a line and I can give you more insights into my script. That should save you time.
See below an overview of the needed API endpoint calls.
1. /api/v1/knowledge_bases/[KB_ID]
to get
- category_ids[]
- answer_ids[]
2. Loop /categories/ with category_ids[] i.e. 479
/api/v1/knowledge_bases/[KB_ID]/categories/[CATEGORY_ID]
to get
{
"id": 479,
"parent_id": 476,
"translation_ids": [
321
],
"answer_ids": [
2706,
...
],
"child_ids": [
479
],
- translation_ids[]
- answer_ids[]
3. Loop /answers/ with answer_ids[] i.e. 2706
/api/v1/knowledge_bases/[KB_ID]/answers/[ANSWER_ID]
to get
- {
"id": 2706,
"assets": {
"KnowledgeBaseAnswer": {
"2706": {
"id": 2706,
"category_id": 479,
"position": 3,
...
"translation_ids": [
2705 // Use to get translated answer content, see 4.
],
"attachments": [],
"tags": []
}
},
- "KnowledgeBaseCategory"[
"translation_ids": [
321
],
]
- "KnowledgeBaseCategoryTranslation": {
"321": {
"id": 321,
"title": "CURRENT-CATEGORY-TITLE", // Category 479
...
}
"318": {
"id": 318, // Category 476 (parent_id of category 479)
"title": "PARENT-CATEGORY-TITLE",
...
}
"317": {
"id": 317, // Category 475 (parent_id of category 476)
"title": "PARENT-CATEGORY-TITLE",)
...
}
]
4. Get translated answer body content
/api/v1/knowledge_bases/[KB_ID]/answers/2706?include_contents=2705
- in
"KnowledgeBaseAnswerTranslationContent": {
"2705": {
"id": 2705,
"body": "<div>translated body of answer 2706 with translation_id 2705</div>",
"attachments": []
}
}
Finally, an answer to my original question about all possible API endpoints. This command can give some hints (as mentioned in another article):
zammad run rails routes