I have created a function with Kotlin using azure-functions-kotlin-archetype. I have created a Http Trigger and a cosmos input binding to read data from the cosmos. I have mentioned sql query also to fetch the data. I want to pass path variable to the http trigger which should be used as parameter in the query. As per Microsoft documentation I have defined the path parameter accordingly. https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=java#http-trigger-get-multiple-docs-from-route-data-using-sqlquery-java
But I am getting blank response, means no data is fetched. If I hard code the parameter in the Sql query, I able to fetch the data. Can any one please tell me the issue here. The Function Code is as below
@FunctionName("GetData")
fun run(
@HttpTrigger(
name = "req",
methods = [HttpMethod.GET],
authLevel = AuthorizationLevel.ANONYMOUS,
route = "/api/getItems/{id}/{qnt}"
)
request: HttpRequestMessage<Optional<String>>,
@CosmosDBInput(
name = "cosmosdb",
databaseName = "item-db",
collectionName = "item",
sqlQuery = "SELECT * FROM ITEM n where n.id= {id} "
+"and n.qnt = {qnt}",
connectionStringSetting = "Cosmos_DB_Connection_String"
)
rs: Array<String>,
context: ExecutionContext): HttpResponseMessage {
return request
.createResponseBuilder(HttpStatus.OK)
.body(rs)
.build()
}
}
route
when you request function with hard code sqlQuery ? – Hury Shen/
beforeapi/getItems/{id}/{qnt}
in yourroute
? – Hury Shenid
andqnt
, also please provide a sample ofsqlQuery
when you request it hard code. – Hury Shen