Azure Functions Http 触发器 - DocumentDB 输出集成 Microsoft.Azure.Documents.Client:值不能为 null
Azure Functions Http trigger - DocumentDB out Integration Microsoft.Azure.Documents.Client: Value cannot be null
我正在尝试将文档添加到我的 DocumentDB,并将传入的有效负载添加到 HttpTriggered Azure 函数。这是function.json内容:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "documentDB",
"name": "email",
"databaseName": "crawler",
"collectionName": "SendGrid",
"createIfNotExists": true,
"connection": "noho_DOCUMENTDB",
"direction": "out"
}
],
"disabled": false
}
这是我的职能:
module.exports = function (context, req) {
try{
if (req.body) {
context.bindings.email = req.body;
context.res = {
status: 200,
body: req.body
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
} catch(e) {
context.log(e);
context.res = {
status: 500,
body: e
};
}
context.done();
return req.body;
};
在处理输入 POST 请求时失败并抛出异常,并显示以下消息:
Exception while executing function: Functions.SendGridJs.
Microsoft.Azure.Documents.Client: Value cannot be null.
Parameter name: document.
我已经通过 Azure Functions 集成向导设置了集成,而不是通过代码部署。所以,我假设 Azure 负责设置代码。
您的 function.json
和 index.js
的代码都可以。您需要将有效的 JSON 字符串输入 req.body
。
这是我的测试截图。
如果我在请求正文中指定无效 JSON,我将得到与您相同的错误。
我正在尝试将文档添加到我的 DocumentDB,并将传入的有效负载添加到 HttpTriggered Azure 函数。这是function.json内容:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "documentDB",
"name": "email",
"databaseName": "crawler",
"collectionName": "SendGrid",
"createIfNotExists": true,
"connection": "noho_DOCUMENTDB",
"direction": "out"
}
],
"disabled": false
}
这是我的职能:
module.exports = function (context, req) {
try{
if (req.body) {
context.bindings.email = req.body;
context.res = {
status: 200,
body: req.body
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
} catch(e) {
context.log(e);
context.res = {
status: 500,
body: e
};
}
context.done();
return req.body;
};
在处理输入 POST 请求时失败并抛出异常,并显示以下消息:
Exception while executing function: Functions.SendGridJs.
Microsoft.Azure.Documents.Client: Value cannot be null.
Parameter name: document.
我已经通过 Azure Functions 集成向导设置了集成,而不是通过代码部署。所以,我假设 Azure 负责设置代码。
您的 function.json
和 index.js
的代码都可以。您需要将有效的 JSON 字符串输入 req.body
。
这是我的测试截图。
如果我在请求正文中指定无效 JSON,我将得到与您相同的错误。