Google Datastore Runquery provides http client to perform GQL query as like below:
POST https://datastore.googleapis.com/v1/projects/my-project-id:runQuery?key={YOUR_API_KEY}
{
"gqlQuery": {
"queryString": "SELECT * FROM User WHERE email = 'user@example.com'"
}
}
But I am getting error response like:
{
"error": {
"code": 400,
"message": "Disallowed literal: 'user@example.com'.",
"status": "INVALID_ARGUMENT"
}
}
But, Google Cloud Datastore Http Client
work perfectly with simple query like 'Select * from User'
.
So, How can this GQL Query be executed with Datastore Http client?
You have to set the allowLiterals parameter to true or use bindings for the parameters (either named or positional).
See the documentation below:
https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#GqlQuery
So if you want to allow literals (constant values) in the query, you should change the request to
{
"gqlQuery": {
"queryString": "SELECT * FROM User WHERE email = 'user@example.com'"
"allowLiterals": true
}
}