2017-07-25 54 views
0

我试图将文档添加到我的DocumentDB与传入有效负载到HttpTriggered Azure函数。这是function.json内容:Azure函数Http触发器 - DocumentDB出集成Microsoft.Azure.Documents.Client:值不能为空

{ 
"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请求:

执行函数时发生异常:Functions.SendGridJs。

Microsoft.Azure.Documents.Client:值不能为空。

参数名称:文档。

我已经通过Azure功能集成向导而不是通过代码部署来设置集成。所以,我假设Azure正在照顾设置代码。

回答

2

您的function.jsonindex.js的代码都可以。您需要将有效的JSON字符串输入req.body

这是我的测试截图。

enter image description here

如果我在请求体指定无效的JSON,我会得到相同的错误你的。

enter image description here