2
votes

Referring to this azure documentation and this using parameters from http trigger

It refers specifically to

 "id" : "{queueTrigger_payload_property}",
 "partitionKey": "{queueTrigger_payload_property}",

If I have an javascript function, an http Trigger which provides a JSON packet in the body. How do I use the Azure cosmos db bindings to get a document using the binding to pass the http json value to the cosmos db query?

I expect similar to this :

"sqlQuery": "SELECT * from c where c.departmentId = {departmentId}",

except that the {departmentId} should be a property from the httptrigger (named req) ?

thus the function.json looks like this:

{
       "authLevel": "function",
       "type": "httpTrigger",
       "direction": "in",
       "name": "req"
     }, {
      "type": "documentDB",
      "name": "inputDocument",
      "databaseName": "mydb",
      "collectionName": "things",
      "partitionKey": "/things/thingid",
      "connection": "my_DOCUMENTDB",
      "direction": "in",
      "sqlQuery": "Select * from things s where s.thingid={httpTrigger_body_thingid}"
    }

The http Trigger in javascript would look like this in the function, which works: req.body.thingid, however binding to the input results in errors, "property not defined" so how do I use an HTTP Trigger input to get a value from a json packet to query cosmos db in the first input, all in the same function?

1

1 Answers

3
votes

It should be just {thingid}:

{
  "type": "documentDB",
  "name": "inputDocument",
  "databaseName": "mydb",
  "collectionName": "things",
  "connection": "my_DOCUMENTDB",
  "direction": "in",
  "sqlQuery": "select * from things s where s.thingid={thingid}"
}

For a POST request like

{
  "thingid": "293a2fc3-799f-4669-92d3-3413f1afa51e"
}

it will deliver the documents in context.bindings.inputDocument (javascript array).