Error writing data with output bindings

Jesse Cofie 1 Reputation point
2020-08-14T22:06:31.257+00:00

I have an Azure Cosmos DB input binding from which I can query and view existing records
However, I've added an Azure Cosmos DB & Azure Queue Storage output bindings to my Azure Function, following the tutorial here.
I can read existing records but when I attempt to write a new record to the output bindings, I get the following error

500 Internal Server Error: [Error] Executed 'Functions.add-bookmark' (Failed, Id=71cb1b0d-f4a7-415d-93dc-6f987817d5e4, Duration=181ms)Value cannot be null. (Parameter 'key')  

Here is the code in my Functions index.js file:

module.exports = async function (context, req) {  
    context.log('JavaScript HTTP trigger function processed a request.');  
    var id = req.query.id || (req.body && req.body.id);  
  
    if(id) {  
        var bookmark = context.bindings.bookmark;  
        if( bookmark){  
            context.res = {  
                status: 422,  
                body : "Bookmark already exists.",  
                headers: {  
                'Content-Type': 'application/json'  
                }  
            };  
        }  
        else {  
              
            // Create a JSON string of our bookmark.  
            var bookmarkString = JSON.stringify({   
                id: req.body.id,  
                url: req.body.url  
            });  
  
            // Write this bookmark to our database.  
            context.bindings.newbookmark = bookmarkString;  
  
            // Push this bookmark onto our queue for further processing.  
            context.bindings.newmessage = bookmarkString;  
  
            // Tell the user all is well.  
            context.res = {  
                status: 200,  
                body : "bookmark added!",  
                headers: {  
                'Content-Type': 'application/json'  
                }  
            };  
        }  
    } else {  
        context.res = {  
            status: 400,  
            body : "You need to supply an id to lookup or insert a bookmark.",  
            headers: {  
                'Content-Type': 'application/json'  
            }  
        };  
    }  
      
    context.done();  
}  

Any idea what is wrong with the code? Any help will be appreciated, Thanks.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,610 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,528 questions
{count} votes