Forum Discussion
QnA Maker API - How to programatically delete structured QnA files?
Hi Dhina,
I tried to reproduce your suggestion. I submitted your JSON but the Ids got ignored again.
What I did is I used the patch snippet from
https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/java#Update
to submit your JSON. If I download the knowledge base, I receive the following
{
"qnaDocuments": [
{ "id": 188, "answer": "You can change the default message if you use the QnAMakerDialog. See this for details: https://docs.botframework.com/en-us/azure-bot-service/templates/qnamaker/#navtitle",
"source": "Custom Editorial",
"questions": [ "How can I change the default message from QnA Maker?" ],
"metadata": [],
"alternateQuestionClusters": [],
"changeStatus": "Update",
"kbId": "..."
},
{
"id": 189,
"answer": "You can use our REST apis to manage your KB. See here for details: https://westus.dev.cognitive.microsoft.com/docs/services/58994a073d9e04097c7ba6fe/operations/58994a0...",
"source": "Custom Editorial",
"questions": [ "How do I programmatically update my KB?" ],
"metadata": [],
"alternateQuestionClusters": [],
"changeStatus": "Update",
"kbId": "..." }
]
}
As you see, the ids 188 and 189 rather than 3001 and 3002.
Is there anything obvious what I can do wrong at client side to have the Ids not be used within the QnA Maker?
Best regards
Christian
Interesting. But, after you had submitted the JSON with 3001 and 3002, did you try deleting by passing either 3001 or 3002 as parameters? I am asking because, in my case, when I used these ids in my delete payload, the article got deleted (which I confirmed using the TEST button). That indicates to me that the IDs are intact.
- ChristianGrossJan 10, 2019Copper Contributor
Hi Dhina,
the thing is that
{
"delete": {
"sources": [
"Custom Editorial"
]
}
}
in your above JSON empties the entire source. Thus, not only document 3001 is deleted but in my tests also document 3002.
Thank you and best regards
Christian
- dhinagajaJan 12, 2019Copper Contributor
Hi Christian,
The JSON payload that I provided in my earlier post had the "ID" as well in it, but yours did not have it, so I guess it ended up deleting all.
Here is the JSON payload once again for your reference:
{
"delete": {
"ids": [
3001
],
"sources": [
"Custom Editorial"
]
}
}
- murad786Oct 08, 2019Copper Contributor
Yes internal id's get created for the questions that a created programatically using API. what i can think of is to specify some metadata (key-value pair) that you can use further to identify the question that you just have created in the KB. you may need to follow several step for deletion. First, you can get the KB JSON using an API Call, Next you need to parse and filter the response JSON. This may include several steps i.e. first you need to extract 'qnaDocuments' array (array that contains all the questions from KB) from JSON, then you need to filter 'qnaDocuments' array by the 'Source' that you had specified while creating the questions. From here you can get the id's of all questions pertaining to that particular source. Next you need to further filter this by metadata that you need to provide to uniquely identify each questions that you create through API which can further provide you the internal id of the question that you need to delete. Rest is simple API call to delete the question using the returned id.
hope this will help dhinagaja