I'm trying to consume Azure REST API to update the Knowledge Base I created via QnA Maker. There's a link there to go to the API testing console.
I'm trying to use the code below to replace the contents of my Knowledge Base with something that I pull from a different data source. See my code below. hopefully it makes sense
function synchronize() {
var jsonData = {
"add": {
"qnaList":[
{"source": "Custom"},
{"answer": "Hello"},
{"questions": ["Hi", "Hello"]}
],
},
"delete": {
"sources": ["Custom"]
},
"update": {}
}
var request = new XMLHttpRequest();
var parameters = {
"body": jsonData
}
request.open("POST", "https://qnawcfaq.azurewebsites.net/qnamaker/knowledgebases/{kbId}}/generateAnswer", true);
request.setRequestHeader("Authorization", "EndpointKey {key}}");
request.setRequestHeader("Content-type", "application/json");
request.onreadystatechange = function () { //Call a function when the state changes.
if (request.readyState == 4 && request.status == 200) {
alert(request.responseText);
}
}
request.send(JSON.stringify(parameters));
}
I am expecting something like the following:
{
"operationState": "NotStarted",
"createdTimestamp": "2018-03-19T07:38:46Z",
"lastActionTimestamp": "2018-03-19T07:39:29Z",
"userId": "86bb8390-56c0-42c2-9f81-3de161981191",
"operationId": "03a4f4ce-30a6-4ec6-b436-02bcdf6153e1"
}
However, I get the following error:
{
"error": {
"code": "BadArgument",
"message": "Authorization"
}
}
The value that I used in the Ocp-Apim-Subscription-Key works against their API Testing Console but it doesn't work with the code above. Any idea what I'm missing here?
Thanks!
Working Solution Uploaded in Github: Solution