Select to view content in your preferred language

Is it possible to post a JSON in Request Body to ArcGIS REST APIs?

160
5
Jump to solution
Tuesday
Labels (1)
DavidLovesArcGIS
Occasional Contributor

We want to do API calls from an integration application, which can do HTTPs calls only, to ArcGIS Enterprise REST APIs. We got the API calls working via x-www-form-urlencoded Body or form-data Body or via url parameters, but we prefer to post a JSON body to ArcGIS REST API. However we can't get a valid response when we enter JSON in the body of a request. Is is possible to post a JSON to ArcGIS REST APIs?

Request url: https://arcgis-acc.<org>.com/un_edit/rest/services/UtilityNetwork/un_edit/FeatureServer/910/query?to...

Request method: POST

Request body: {"where": "1=1","outFields": "*","returnGeometry": true,"f": "json"}

Response HTML page of featureServer - 910 with errors: Unable to complete operation. Unable to perform query operation.

 

 

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

I have never seen any documentation stating or showing it is supported, so I am going with, "it isn't supported."  Empirically, your testing also indicates it isn't possible.

View solution in original post

5 Replies
JoshuaBixby
MVP Esteemed Contributor

I have never seen any documentation stating or showing it is supported, so I am going with, "it isn't supported."  Empirically, your testing also indicates it isn't possible.

TimWestern
MVP

The issue is the json flag needs to be in the query submitted.  if you go to one of the forms:

At the end of the url if it has this parameter &f=pjson  it should accept and receive json>?

(I don't think this is technically an arcgis thing, but how react and http requests work)

So if you submit to the query? an expression like:

 

FeatureServer/7/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&relationParam=&returnGeodetic=false&outFields=*&returnGeometry=true&returnCentroid=false&returnEnvelope=false&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&defaultSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson

 



that ends in &f=pjson that should return json

note, this only works if the endpoint, the featureserver REST Url is able to be called publicly, if it requires authentication of some kind (shared not with all, but only with certain groups or users), then you need a valid token for that group or user added to the query string)


Additional things to consider:

When you do a query via a rest URL, the parameters submitted in the 'query string' are encoded. the first query parameter is prefixed by a ? followed by a keyname={value} (where {value} is the actual value braces not needed.

So a common one I do is go to the where section and put 1=1 (so its true)

this would encode as:

where=1%3D1

and so on, I think there has to be a valid query, and you need at least one outfield set for it to work.  (if your service doesn't use outfields, then it might be different, but most I've seen have that as a parameter for the query)

The last project I did something like this I built the query in code, into one string and tacked it into the baseurl and feature/url in the manner above to make the call.

0 Kudos
DavidLovesArcGIS
Occasional Contributor

Thanks for suggestion Tim to use f = json in url parameters to ArcGIS server, which should then be able to receive JSON. In our case we use a privately hosted ArcGIS Enterprise environment and unfortunately it does not receive JSON if we specify f=json in url parameters or in body. We still get the below error:

{
    "error": {
        "code": 400,
        "message": "Unable to complete operation.",
        "details": [
            "Unable to perform query operation."
        ]
    }
}

 

0 Kudos
TimWestern
MVP

f=json i think impacts how it returns the data.  If a browser is used on the /query it can be html or json.

I think I misunderstood your question.  You are talking about how to send the message.  I thought I had made this work with JSON at a previous project, but since I don't have the source to consult, I'm not sure what else I could say that would help.



I did find this nugget which might be important:

https://developers.arcgis.com/rest/services-reference/enterprise/get-started-with-the-services-direc... 

Get Request URLS have a limit of 1024 characters, I had not seen that limitation specified previously., the note suggests certain types of apps may find this limit as 2048... not sure why the difference though.

TimWestern_0-1737553232437.png

This then does say what  @JoshuaBixby I think was alluding too:

TimWestern_1-1737553348994.png



So while that parameter I suggested might help in the query strings for output it won't change the content-type the server expects, so I think Joshua was correct after all.




DavidLovesArcGIS
Occasional Contributor

Thx for checking Tim! Yeah indeed in the documentation it seems for POST requests you always need to use application/x-www-form-urlencoded and can't use JSON unfortunately.

0 Kudos