I have an ArcGIS layer published to my local server at:


I want to dynamically construct the query where clause for this layer based on the URL. For example:


would effectively translate into the following where clause:


How can I accomplish this?

The arcgsis documentation touches on the topic:




And I've tried:


and then,in definition query: category=::category

But it doesn't work, ArcMap throws an SQL syntax error.

Update: this question is specifically on how defining ArcGIS layers. This is not a question on how to retrieve GET query parameters in PHP, JavaScript or any common programming langauge.

3 Answers 3


if you're using javascript, you can create a query from your feature layer https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#createQuery

var layer = new FeatureLayer({
  url: "https://baseURL/myMapServer/0"

var queryParams = layer.createQuery();
queryParams.where = "category = 'cat1'";


or if you want to build the URL : https://baseURL/myMapServer/0/query?where=category%3D'cat1'


What are you using on your local server?

What you have is a GET request. With PHP for example, you need to do something along the lines of:

$cat = $_GET['category'];

This will assign the value - in your example of "cat1" - to the variable $cat. You then proceed with building your SQL query and adding the $cat variable at the appropriate location.

Anyway, you need to look into how to grab the value of your GET request. I hope this helps.

  • I don't think you understood the question. This is about arcgis, not how to retrieve query parameters from a GET request.
    – Ya.
    Dec 11, 2019 at 14:55

This is a very ambiguous request. If I understand correctly you need to extract info from a call (GET request) to ArcGIS Server's REST endpoint, so you already have the complete URL (generated from some app perhaps). In this case:

//example URL: http://baseURL/arcgis/rest/services/myMapServer/0/query?where=NAME+like+%27%25test%25%27+AND+OBJECTID+%3C+1000&f=html
const mySearchParams = new URLSearchParams(window.location.search)
for (const [key, value] of mySearchParams) { do what you want with them ... }

If you want to you can only get the where param:

//"NAME like '%test%' AND OBJECTID < 1000"

Read here:



Otherwise take a look at the ArcGIS Server REST API, more specifically the Query operation on a Map/Feature Service/Layer: https://developers.arcgis.com/rest/services-reference/query-map-service-layer-.htm You can play with the web UI, there is a where clause you can apply as well. The bad part is all other params get included in the GET request with no values. Another VERY BAD "feature" of ArcGIS Server is that to this day it still responds with HTTP 200 to failed requests ...

  • This to clarify, this question is specifically on how to define an arcgis layer ousing Arc Map in a way that would let me access the query parameters and use them in the underlying SQL query. This is not a question on how to access query parameters in a GET request.
    – Ya.
    Dec 11, 2019 at 15:53
  • Yeah, I didn't understand the question, I see you have updated it. :) So it's about query layers in ArcMap. Dec 11, 2019 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.