cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Newbie

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

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>&pass...

Any suggestions or tips?

Thanks

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

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

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=applica...

View solution in original post

10 REPLIES 10

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

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)

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

In addition, you may use Postman:

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

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

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

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

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

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.

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

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=applica...

View solution in original post

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

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.

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

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.

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

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.