【发布时间】:2019-04-06 01:52:28
【问题描述】:
我正在尝试使用 Azure REST API 来更新我通过 QnA Maker 创建的知识库。那里有一个链接可以转到API testing console。
我正在尝试使用下面的代码将我的知识库的内容替换为我从其他数据源中提取的内容。请参阅下面的代码。 希望这是有道理的
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));
}
我期待以下内容:
{
"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"
}
但是,我收到以下错误:
{
"error": {
"code": "BadArgument",
"message": "Authorization"
}
}
我在 Ocp-Apim-Subscription-Key 中使用的值适用于他们的 API 测试控制台,但不适用于上面的代码。知道我在这里缺少什么吗?
谢谢!
在 Github 上上传的工作解决方案: Solution
【问题讨论】:
-
你的 uri 是错误的并且标题“Ocp-Apim-Subscription-Key”到
-
@FrV,你能提供正确的 uri 和标题吗?你能提供一个例子吗?谢谢!
标签: qnamaker