@OLADOJA NIYI SAMAD Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
I understand that you have an Azure Function App which is configured for the HTTP trigger with CosmosDB output binding and you are encountering the below error:
Microsoft.Azure.DocumentDB.Core: Value cannot be null. (Parameter 'serviceEndpoint').
Is theserviceEndpoint
the connectionString to Cosmos DB? Have you set that under app settings in Azure?
Looking at the error message it seems like this serviceEndpoint
value is not set. I am suspecting it's the connectionString. So you may need to check what the serviceEndpoint
is ? and where is it set in your code ?
You can leverage the below sample which I have developed. It is configured for the HTTP trigger with CosmosDB output binding. So depending upon the HTTP Get, POST operation invoke, I am logging the request details in cosmsoDB and it is working fine.
Function1.cs
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Configuration;
using Microsoft.WindowsAzure.Storage.Queue.Protocol;
namespace OutCosmosHTTPTrigger
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[CosmosDB(
databaseName: "testdb",
containerName: "testcontainer",
Connection = "CosmosDBConnection")] IAsyncCollector<dynamic> documents,
ILogger log)
{
dynamic document = new { Description = req.Body.ToString(), id = Guid.NewGuid() };
await documents.AddAsync(document);
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkResult();
}
}
}
Here is my local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"CosmosDBConnection": "AccountEndpoint=https://cosmosdb123.documents.azure.com:443/;AccountKey=XXXXXXXXXXXX;"
}
}
Here is the output console logs after I invoked the GET and POST operation while executing my Function APP:
Here is the entity saved in the CosmosDB :
Hope this helps.
I am sharing a few related articles here if that helps:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-output?tabs=python-v2%2Cin-process%2Cfunctionsv2&pivots=programming-language-csharp
https://learn.microsoft.com/en-us/answers/questions/196212/error-when-using-cosmosdb-in-python-function-on-az
https://github.com/MicrosoftDocs/azure-docs/issues/33312
**
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.