Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I have a data table that I would like to call the QueryDataTableEntries service on through a REST API call.
I have tried the following on my browser with nothing being returned:
Any suggestions or tips?
Thanks
Solved! Go to Solution.
You'd have to use URL encoding to pass the json, so for example if i do a timestamp query on my QueryDataTableEntries service, my json looks like this
{"filters":{"type":"AND","filters":[{"fieldName":"timestamp","type":"BETWEEN","to":1435581955257,"from":1435553155257}]}}
Then I use this tool https://www.url-encode-decode.com/
to get this %7B%22filters%22%3A%7B%22type%22%3A%22AND%22%2C%22filters%22%3A%5B%7B%22fieldName%22%3A%22timestamp%22%2C%22type%22%3A%22BETWEEN%22%2C%22to%22%3A1435581955257%2C%22from%22%3A1435553155257%7D%5D%7D%7D
Then my query (note this is missing the auth because i'm already authorized in the same browser session)
Please refer to the following REST API Overview and Examples
You may also find helpful to utilize your browser dev tools in which you can see the structure of every request (f12 in chrome)
In addition, you may use Postman:
*Im planning to run this REST request in Objective-C for a native mobile app, so I am not sure how I could translate the syntax from a web tool or Postman as just a string/url.
You would be passing it as a string/url; web tool is just for your reference on the call construction.
Right, but whats the string structure for the query section exactly? Not sure how i will go about finding certain records that match certain values for instance.
You'd have to use URL encoding to pass the json, so for example if i do a timestamp query on my QueryDataTableEntries service, my json looks like this
{"filters":{"type":"AND","filters":[{"fieldName":"timestamp","type":"BETWEEN","to":1435581955257,"from":1435553155257}]}}
Then I use this tool https://www.url-encode-decode.com/
to get this %7B%22filters%22%3A%7B%22type%22%3A%22AND%22%2C%22filters%22%3A%5B%7B%22fieldName%22%3A%22timestamp%22%2C%22type%22%3A%22BETWEEN%22%2C%22to%22%3A1435581955257%2C%22from%22%3A1435553155257%7D%5D%7D%7D
Then my query (note this is missing the auth because i'm already authorized in the same browser session)
Thanks a lot! This worked. Since I am using objective-c, I used:
NSString *unescaped = @"<json query test>";
NSString *escapedString = [unescaped stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
and appended the escapeString to the rest of my url.
Great to hear! Sorry it took a while for me to provide what you actually asked for -- that's due to my initial misunderstanding of your need.
No worries! I could've definitely phrased my question better.
Do you perhaps know where I can find a guide to construct more complex queries. For example some queries with multiple OR's and AND's and what the json for that will look like?
I appreciate it.
This is not quite my area of expertise, but I would say, this is a good place to start https://www.w3schools.com/js/js_json_intro.asp