0

I am trying to send a request to 'HERE' Geo API from a node.JS code and getting an empty response
This is what i am doing:

const fetch = require('node-fetch');
const http = require('http');
const https = require('https');
const keepAliveAgent = new https.Agent({
    keepAlive: true
});

var lat = '43.293162'
var long = '-85.920004'
var endpoint = 'https://revgeocode.search.hereapi.com/v1/revgeocode?at=' + lat + '%2C' + long + '&apiKey={API_key}'
console.log(endpoint)
here = async function (endpoint) {
    var start_time = new Date().getTime();

    let response = await fetch(endpoint, {
        method: 'GET',
        agent: keepAliveAgent

    });
    console.log(response)
    var time = { 'Here Response': + (new Date().getTime() - start_time) + 'ms' };
    console.log(time)
    return [response.json(), time];

}

The response is:

[
    {},
    {
        "Here Response": "781ms"
    }
]

When i am using the same URL with a GET request in postman i am getting the right response enter image description here What am i doing wrong?

8
  • Can you try putting , instead of %2C? Commented Jul 14, 2020 at 9:27
  • Could you please tell which Here Geo API are you using? A URL would be better. Commented Jul 14, 2020 at 9:40
  • I tried using ',' instead of %2C i still got an empty response Commented Jul 14, 2020 at 9:44
  • The URL i am using is revgeocode.search.hereapi.com/v1/…{APIKEY} Commented Jul 14, 2020 at 9:44
  • @OferB I'm asking about the API name. Could you tell me the API name or provide me the URL of the API documentation? Commented Jul 14, 2020 at 9:49

1 Answer 1

1

I used this code and it worked
Thanks

const fetch = require('node-fetch');
const http = require('http');
const https = require('https');
const keepAliveAgent = new https.Agent({
    keepAlive: true
});

var lat = '43.293162'
var long = '-85.920004'
var endpoint = 'https://revgeocode.search.hereapi.com/v1/revgeocode?at=' + lat + '%2C' + long + '&apiKey={API_key}'
console.log(endpoint)
here = async function (endpoint) {
    var start_time = new Date().getTime();

       let response = await fetch(endpoint, {
      method: 'GET',
      redirect: 'follow',
      agent: keepAliveAgent ,
      
    })
  let data = await response.json()
  console.log(data) 
  var time = { 'Here Response': + (new Date().getTime() - start_time) + 'ms' };
  console.log(time)
  return [data];

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.