Value cannot be null. (Parameter 'containerId')" error.

RangerSayip 0 Reputation points
2024-09-10T12:23:46.57+00:00

I've been exploring Azure and working with Functions and CosmosDB recently. I followed the setup instructions from this learn.microsoft.com resource, but I keep running into an Internal Server Error 500. The logs indicate a "Value cannot be null. (Parameter 'containerId')" error. Below are the configurations I've used. I came across some online discussions suggesting that I should use 'containerName' instead of 'collectionName'. However, when I attempt to update this in the function.json file, my changes don't stick; the file reverts to 'collectionName' after I refresh the page. Could someone guide me on how to resolve these issues ?

index.js

module.exports = function (context, req) {

    var bookmark = context.bindings.bookmark

    if(bookmark){
        context.res = {
        body: { "url": bookmark.url },
        headers: {
            'Content-Type': 'application/json'
        }
        };
    }
    else {
        context.res = {
            status: 404,
            body : "No bookmarks found",
            headers: {
            'Content-Type': 'application/json'
            }
        };
    }

    context.done();
};
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name": "bookmark",
      "direction": "in",
      "type": "cosmosDB",
      "partitionKey": "/id",
      "methods": [],
      "databaseName": "func-io-learn-db",
      "collectionName": "Bookmarks",
      "connectionStringSetting": "learndb_DOCUMENTDB",
      "id": "{id}"
    }
  ]
}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,085 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 15,886 Reputation points Microsoft Employee
    2024-09-10T21:58:20.49+00:00

    Hi @RangerSayip Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    I did try out the steps provided in the article and could modify the function.json file multiple times without any issues. You could be facing a browser cache issue or an intermittent platform error which might be preventing from making changes to the file. If you continue to face this error, please create a new function within the Function app and see if it works as expected.

    "Value cannot be null. (Parameter 'containerId')"

    As you identified in your research, referencing the CosmosDB with CollectionName in the bindings would result in this error. Instead, use ContainerName

    I have further noticed that you are setting the partitionKey property as /id According to the documentation, this has to be set as {id}. With the current configuration you have, even though you modify the containerName in the bindings, you would still see No bookmarks found error when you try to access the CosmosDB data. Please refer the following set of binding that I have tested and could confirm the working behavior

    {
      "bindings": [
        {
          "authLevel": "function",
          "type": "httpTrigger",
          "direction": "in",
          "name": "req",
          "methods": [
            "get",
            "post"
          ]
        },
        {
          "type": "http",
          "direction": "out",
          "name": "res"
        },
        {
          "name": "bookmark",
          "direction": "in",
          "type": "cosmosDB",
          "partitionKey": "{id}",
          "databaseName": "func-io-learn-db",
          "containerName": "Bookmarks",
          "connection": "funcappcosmos_DOCUMENTDB",
          "id": "{id}"
        }
      ]
    }
    

    Hope this helps! If you keep encountering the same error even with the newly created function, please let us know and we would be able to help you further.

    Update

    Issue resolved by creating the Azure function through Azure CLI.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.