Hi all,
I'm trying to geocode some addresses with API Geocoding, in Hana XSJS.
I made a GET request to geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?<parameters>, where in the paremeters I inserted
Solved! Go to Solution.
I solved by myself because the problem was in the Hana Trust Score, I had to create a new trust score and link the configuration file .xshttpdest to make the request.
Thanks to everyone!
That's strange,
I just did it as you said (same as the Postman example) and it worked:
curl --location --request GET 'https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?token=MY_API_KEY&f=pjson&singleLine=1600 Pennsylvania Ave NW, DC'
but it seems that the request doesn't return anything. Can someone help me?
Hi thanks for the answer.
req = new $.web.WebRequest($.net.http.GET, "f=pjson&singleLine=" + address +"&token="+access_token);
response = client.getResponse()');
response = client.request(req, dest).getResponse();
jresponse = JSON.parse(response.body.asString());
in the 4th row of code I parse the the string into json, but while I access to the response object the code crashes.
It seems like the response is an empty object, maybe because of the wrong request
Have you tried:
try{
// ...
}catch(e){
console.log("Error: ", e);
}
It might be an HTML been responded by the API?
sadly the language is not javascript but XSJS (SAP Hana Javscript Language) so I can't print with console.log().
Anyway I have a function to write into a SQL table to log in wich point my code stop, that's why I know that's somethig wrong when I access to response object.
For example the code crashes even in this snippet:
req = new $.web.WebRequest($.net.http.GET, "f=pjson&singleLine=" + address +"&token="+access_token);
response = client.getResponse()');
response = client.request(req, dest).getResponse();
printInLogDB(idStep,'X',response.body.asString());
Since XSJS is a service itself, you can forward the error message as part of the service response and then analyze it in the debug console of your browser. Just checked one of my xsjs project and found this sample code.
function doGet() {
try{
$.response.contentType = "application/json";
$.response.setBody(JSON.stringify(getProperties()));
}
catch(err){
$.response.contentType = "text/plain";
$.response.setBody("Error while executing query: [" + err.message + "]");
$.response.returnCode = 200;
}
}
The basic operation appears to be correct. Using your exact parameters in a web browser you can see it works (you need to replace your token)
Response:
{ "spatialReference": { "wkid": 4326, "latestWkid": 4326 }, "candidates": [ { "address": "1600 Pennsylvania Ave NW, Washington, District of Columbia, 20500", "location": { "x": -77.036546998208649, "y": 38.897675107651253 }, "score": 100, "attributes": { }, "extent": { "xmin": -77.037546998208654, "ymin": 38.896675107651255, "xmax": -77.035546998208645, "ymax": 38.89867510765125 } } ] }
1. verify your URL is correct?
2. verify you are URL encoding the address string?
3. verify your token is correct?
@LeonardoRomanato are you certain line 2 is correct?
response = client.getResponse()'); response = client.request(req, dest).getResponse();
As John highlighted, my two cents would go for the encoding of the address. You can avoid encoding it if you uses a POST request instead.
@LeonardoRomanato were you able to fix this?