0

How to write the postgres sql body in Hasura data api to get some result by taking input from user. The sql query is like"Select moviedetails from table name where movie_name='name enterd by user'.I want to know the structure to accept data from user

url = "https://data.incipiently69.hasura-app.io/v1/query"

This is the json payload for the query

requestPayload = { "type": "select", "args": { "table": "collect", "columns": [ "overview" ] } }

Setting headers

headers = { "Content-Type": "application/json" }

Make the query and store response in resp

resp = requests.request("POST", url, data=json.dumps(requestPayload), headers=headers)

resp.content contains the json response.

print(resp.content)

1 Answers1

1

You would just need to substitute data retrieved from the user input in the where clause of the API query.

user_input = req.body.user_input

requestPayload = {
  "type": "select",
  "args": {
    "table": "collect",
    "columns": ["overview", "movie_name"],
    "where": {
        "movie_name": user_input
    }
  }
}
praveenweb
  • 743
  • 4
  • 15