Forum Discussion

radhika_kundana's avatar
3 years ago

Endpoint: External api gives in correct json data

Hi,

I am able to retrieve user location using bing api.

Environment: staging

Issue here is:  When I try to call bing api with Ajax, it gives me correct user location. 

When I call same api using endpoint + http.client.request, api gives me in-correct solution. 

 Are there any proxy settings blocking endpoint to provide correct location in Khoros staging? 

  • Thanks for your inputs.

    I was able to make it work by passing ip address in headers.

    <#assign response = http.client.request("api").header("X-FORWARDED-FOR",ipaddress).get()/>

  • MattV's avatar
    MattV
    Khoros Staff

    http.client.request makes the call from the server the community is running on, so the result returned would be the location for the server, not the user. If the Bing API lets you pass an IP or something then you'd have to get the users IP with freemarker and pass that to the Bing API.

    • Thankyou MattV for reply.

      How can I get users(anonymous/logged in user) Ipaddress in freemarker? 

      below request provides server IP address but not users. 

      ${http.request.remoteAddr} 

  • MattV's avatar
    MattV
    Khoros Staff

    http.request.remoteAddr returns the IP address of whatever IP made the HTTP request, so you'd have to consider the context of how that code is being called.

    Though I'd expect 99% of the time, it should be returning the IP address of the current user; e.g. if you're testing it, it would be your IP address.

    • Thanks for your inputs.

      I was able to make it work by passing ip address in headers.

      <#assign response = http.client.request("api").header("X-FORWARDED-FOR",ipaddress).get()/>