0

I have the following json sent to an Azure Function App:

{
"a" : {
  "nested" : {
    "object" : "hello_world"
    }
  }
}

Within the function.json I would like to fetch a document based on the object value (hello_world in this example) :

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "cosmosDB",
      "direction": "in",
      "name": "doc_in",
      "databaseName": "my_db",
      "collectionName": "my_collection",
      "connectionStringSetting": "AZURE_COSMOS_DB_CONNECTION_STRING",
      "sqlQuery": "SELECT * FROM my_db as db WHERE db.my_field = {a.nested.object}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

init.py

def main(req: func.HttpRequest, doc_in: func.In[func.Document]) -> func.HttpResponse:
    if doc_in:
        return func.HttpResponse(
            json.dumps({"msg":"A document was found!"}),
            status_code=200,
            mimetype="application/json" 
            )  

The SELECT * FROM my_db as db WHERE db.my_field = {a.nested.object} query does not work and return a HTTP 404 code and there's no much information in the documentation.

Does someone know how am I supposed to set the input json file into the cosmos query ?

8
  • The JSON is not valid. JSON should be a valid object. Commented Feb 26, 2023 at 22:29
  • Sorry I did the typo while simplifying the json document for the so question - that's fixed now Commented Feb 26, 2023 at 22:32
  • The input parameter is called req. Somehow you need to read from the JSON from the input parameter. I'm not sure if it's possible. Commented Feb 26, 2023 at 22:33
  • Have you tried to run it with the correct JSON? According to the docs, it should work with departmentId being on the first level of the JSON: learn.microsoft.com/en-us/azure/azure-functions/… Commented Feb 26, 2023 at 22:39
  • 1
    It's hard to find any docs 🤷‍♂️ Commented Feb 26, 2023 at 23:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.