Can I call batch geocoder request with XmlHttpRequest?

0

I'm trying to make a batch geocoding call to here.com API using XmlHttpRequest, and I'm getting no results

According to HERE.COM documentation, I can make a batch geocoding call to

https://batch.geocoder.api.here.com/6.2/jobs?app_id={YOUR_APP_ID}&pp_code={YOUR_APP_CODE}&mailto=<your_email_address>&outdelim=|&outcols=displayLatitude,displayLongitude,locationLabel,  houseNumber,street,district,city,postalCode,county,state,country&outputcombined=false

and then, in POST body

recId|searchText|country
0001|Invalidenstra├če 116 10115 Berlin|DEU
0002|Am Kronberger Hang 8 65824 Schwalbach|DEU
0003|425 W Randolph St Chicago IL 60606|USA

I'm trying to get some response using XmlHttpRequest from JavaScript, using this code:

geocode = function()    {
    var xhttp = new XMLHttpRequest();

    var osmURL="https://batch.geocoder.api.here.com/6.2/jobs"
        +"?app_id=0aApOideNwpiPyzejpFk"
        +"&app_code=Hz7Rz_PodmUhdG8KCDSgk_g"
        +"&mailto=joan.the.best@gmail.com"
        +"&outdelim=|"
        +"&outcols=recId,displayLatitude,displayLongitude"
        +"&outputcombined=false"        
        +"&language=de-DE"

    xhttp.onreadystatechange = function() {
        alert(xhttp.responseText);
        if (this.readyState == 4 && this.status == 200) {
            alert(xhttp.responseText);
        }
    };

    xhttp.onload = function() {
        alert(xhttp.responseText);
        alert(this.status);
        if (this.readyState == 4 && this.status == 200) {
            alert(xhttp.responseText);
        }
    };

    var postToSend = 
        "recId|searchText|country" + "\r\n" +
        "0001|Invalidenstra├če 116 10115 Berlin|DEU" + "\r\n" + 
        "0002|Am Kronberger Hang 8 65824 Schwalbach|DEU" + "\r\n" +
        "0003|425 W Randolph St Chicago IL 60606|USA";

    xhttp.open("POST", osmURL, true);
    xhttp.send(postToSend);
}

I expect the output to be something similar to:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
  <Response>
    <MetaInfo>
      <RequestId>qr9jVjuoFe1mULUvBlXr7UK4dM8BpAkO</RequestId>
    </MetaInfo>
    <Status>submitted</Status>
    <TotalCount>0</TotalCount>
    <ValidCount>0</ValidCount>
    <InvalidCount>0</InvalidCount>
    <ProcessedCount>0</ProcessedCount>
    <PendingCount>0</PendingCount>
    <SuccessCount>0</SuccessCount>
    <ErrorCount>0</ErrorCount>
    </Response>
</ns2:SearchBatch>

but no results are returned, even no status. I've done individual calls without problems, so the URL must be reachable.

Have you tried something like this?

Thanks in advance, Joan.

EDIT: Investigating a bit more, I'm getting a "XMLHttpRequest: Network Error 0x80070005, Access is denied" error, and something related to CORS. How can I present valid credentials so Access is allowed? Thanks.

here-api
asked on Stack Overflow Jan 22, 2019 by Joan Segura • edited Jan 22, 2019 by Joan Segura

1 Answer

0

Maybe the encoding of the 'outdelim'-parameter is the culprit; change pipe '|' to '%7C'. This also applies to 'indelim'.

See also The Batch Geocoder API returns only failed status

answered on Stack Overflow Jan 24, 2019 by ckHERE

User contributions licensed under CC BY-SA 3.0