I'm trying to make a query request on my database in back4app using Alamofire. (i don't want to use Parse, for study purpose). My DB has 2 simple field , Name and Age
I would like to send .get request using AF to obtain the data relative to a specific name.
I'm able to retrive all data in the DB with the following function:
func readData(){
AF.request(url!, method: .get, headers: headers).responseJSON { json in
print(json)
}
}
as per the back4app documentation in order to query a specific field is reported: " specified the Parameters where URL parameter constraining the value for keys. It should be encoded JSON"
here my test:
func readDataQuery(name: String){
let param: [String: String] = [
"Name": name
]
AF.request(url!, method: .get, parameters: param, headers: headers)
.responseJSON { json in
print(json)
}
}
but it return an error:
success({
code = 102;
error = "Invalid parameter for query: Name";
})
how can I write the parameters to pass at the request?
thanks
You are getting this error because there is no such query parameter called "Name". In order to get objects via a condition, you would have to use the "where" clause like this.
let param: [String: String] = ["where": "{"Name":"Meimi"}"]
For more information please visit this website
https://docs.parseplatform.org/rest/guide/#query-constraints