Reputation: 614
I'm trying to add a document to my DocumentDB with the incoming payloads to an HttpTriggered Azure Function. This is the function.json content:
{
"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
}
And this is my function:
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;
};
It fails and throws an exception while processing an input POST request with the following message:
Exception while executing function: Functions.SendGridJs.
Microsoft.Azure.Documents.Client: Value cannot be null.
Parameter name: document.
I've setup the integration through the Azure Function integration wizard and not through code deployment. So, I'm assuming that Azure is taking care of the setup code.
Upvotes: 0
Views: 543
Reputation: 9950
Both of your function.json
and code of index.js
are OK. You need to feed valid JSON string into req.body
.
Here is my testing screenshot.
If I specify invalid JSON in the request body, I will get the same error as yours.
Upvotes: 2