How to use Send Web Request activity to get data from Esri enrichment service
Hello, I'm trying to query the Esri enrichment service to return population numbers for a geometry. If I use a simple geometry with a GET, it works fine. For example:
Method: GET
But it breaks down when the geometry is complex, I assume because of the url size limit.
So I'm trying to do a web request with a POST, using the following parameters:
Url: https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer/Geoenrichment/enrich
Method: POST
Headers: ={"Content-Type": "application/x-www-form-urlencoded" }
Form: ={"studyAreas":[{"geometry":{"x":-117.1956,"y":34.057}}],"analysisVariables":["KeyGlobalFacts.TOTPOP"],"f":"pjson","token":"<tokenGoesHere>"}
It returns the following error:
{
"results" : [ {
"paramName" : "GeoEnrichmentResult",
"dataType" : "GeoEnrichmentResult",
"value" : {
"version" : "2.0",
"FeatureSet" : [ ]
}
} ],
"error" : {
"code" : 10020007,
"message" : "Parameter 'studyAreas' is invalid.",
"details" : [ ],
"causes" : [ {
"code" : 10020049,
"message" : "Invalid attribute 'StudyAreas'.",
"details" : [ ]
} ]
},
"messages" : [ ]
}
Any idea what I'm doing wrong?
Thanks,
Chris
-
Hi Chris,
I think the form content needs to be in the same format as the original query string:
Url: https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer/Geoenrichment/enrich
Method: POST
Headers: ={"Content-Type": "application/x-www-form-urlencoded" }
Form: studyAreas=[{"geometry":{"x":-117.1956,"y":34.057}}]&analysisVariables=["KeyGlobalFacts.TOTPOP"]&f=pjson&token=<tokenGoesHere>
Also, not sure if it was a typo, but your initial GET method has a query string that starts with ?&studyAreas= instead of just ?studyAreas=.
0 -
Hi Ken. You were right about the typo in the GET request (although it still works).
I tried your suggestion on the POST method, but it returns an error 404 - unable to process this request. I had used JSON object notation for the form body based on your suggestion on another thread (https://communities.geocortex.com/s/question/0D5f200006MO8kQCAT/help-setting-up-send-web-request-to-get-an-image).
In WF4 it worked using the WebRequest activity, sending a dictionary in the Parameters argument (with "studyAreas" as the key)
Any ideas?
Thanks,
Chris
0 -
Don't you love it when someone contradicts their previous advice? :) Now that I look at it, I realize my first response here was wrong. I was thinking of what should end up being sent in the POST request, but what you had was correct for the inputs to the activity.
Does it work if you send the equivalent data using Postman?
0 -
I'm guessing you're working through this tutorial:
https://developers.arcgis.com/labs/rest/get-demographic-data/
Do you need to add studyAreasOptions?
"studyAreasOptions": { "areaType":"RingBuffer", "bufferUnits":"esriMiles", "bufferRadii":[1] }0 -
I wasn't working through that tutorial, but I installed Postman and followed the directions using just the parameters I used earlier (studyAreas, analysisVariables, f, token). It worked correctly. So the problem is definitely in the way I'm formatting the form parameters
0 -
Aha, got it by looking at the Code and selecting Javascript - Fetch. The correct syntax for the form is:
={"studyAreas":"[{\"geometry\":{\"x\":-117.1956,\"y\":34.057}}]","analysisVariables":"[\"KeyGlobalFacts.TOTPOP\"]","f":"pjson","token":"<tokengoeshere>"}
0 -
Glad you were able to solve it!
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
7 Kommentare