0
votes

Is it possible to retrieve my data in Azure Cosmos in JSON format and share it with someone else without them accessing the actual environment? Something like an HTTP get from sharepoint. I am new to cosmos and APIs, so sorry if I am using the wrong terms here.

enter image description here

Update Attempting Azure Function: enter image description here

I attempted to create an HTTPTrigger. Can I copy and paste the JSON into function.json and javascript into index.js? I changed the databaseName and collectionName, but it doesn't return the cosmos documents.

1
Did you also add your CosmosDB ConnectionString to the settings? A more detailed response code of the function would be helpful. Alternatively, have a look at the beginner's tutorial: docs.microsoft.com/en-us/azure/cosmos-db/… There you have a step-by-step guide of how to set up your function to access your CosmosDB instance.DSpirit
stackoverflow.com/questions/64719494/… I made another post here. I was trying to do it in the portal though. I did add the connection string.williswin
I was able to follow the tutorial and get my query results in a terminal, how would I get this to display in JSON format on a website? Or work with Azure Functions?williswin
Great, so now you have to set your return value to the obtained documents. I found a full example of how to perform CRUD operations on the CosmosDB via Azure Functions on JS: dev.to/vidamrr/…DSpirit

1 Answers

1
votes

General

I think the easiest way to offer someone access to a specified collection would be to create an Azure Function. From the docs:

Azure Functions allows you to run small pieces of code (called "functions") without worrying about application infrastructure. With Azure Functions, the cloud infrastructure provides all the up-to-date servers you need to keep your application running at scale.

A function is "triggered" by a specific type of event. Supported triggers include responding to changes in data, responding to messages, running on a schedule, or as the result of an HTTP request.

C#

Here's an example of how this might look if you want to query documents by id:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=csharp#http-trigger-look-up-id-from-query-string

If you want more complex queries to be executed, take a look at this section of the abovementioned documentation:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=csharp#http-trigger-look-up-id-from-route-data-using-sqlquery

So basically this enables you to provide a HTTP endpoint, that's configured to run specific query against your CosmosDB instance.

JavaScript

An example of how to set up a CosmosDB instance and create functions for CRUD operations in JS can be found here: https://dev.to/vidamrr/cosmos-db-crud-operations-using-azure-functions-4d27