Skip to main content
1-Visitor
November 6, 2017
Solved

How do I structure a query parameter for a REST Call?

  • November 6, 2017
  • 2 replies
  • 11005 views

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:

http://<MyServer>/Thingworx/Things/<MyDataTable>/Services/QueryDataTableEntries?userid=<userId>&password=<password>&query={filters:{type:LIKE, fieldName:<MyFieldName>, value:<MyValue>}}

Any suggestions or tips?

Thanks

Best answer by posipova

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)

http://localhost/Thingworx/Things/DT/Services/QueryDataTableEntries?method=POST&content-type=application/JSON&query=%7B%…

2 replies

20-Turquoise
November 6, 2017

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)

20-Turquoise
November 6, 2017

In addition, you may use Postman:

kbetances1-VisitorAuthor
1-Visitor
November 6, 2017

*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.

20-Turquoise
November 6, 2017

You would be passing it as a string/url; web tool is just for your reference on the call construction.

kbetances1-VisitorAuthor
1-Visitor
November 7, 2017

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.