This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.
Closed

How to get the client's IP address in api.js?

Hi all,

For an app I'm building, I'm exposing an API through Homey, using an api.js file.
So far so good, I've got the basics covered with the direction I want the app to go, and it's working just fine. Based on an API call a flow can be triggered.

However I'd like to identify and authorize the client of the API (i.e. the device that is calling the API through HTTP) by it's IP address.
From what I've found online regarding node.js, a "request" object should be available where a "remoteAddress" property is present. Just what I need.

However, the "fn" property in the module export definition obviously does not contain such a "request" object. Being multi-threaded, a global object for the request should theoretically not exist.

TL;DR: does anyone know of a way to retrieve the client's remote IP address?

Comments

  • api.js is pretty stiped down simple JSON API based on Express framework.
    You have available only following args
    • params - path params
    • body - request body
    • query - query string
    • files - multipart files
    • user - authenticated user
    There are also non documented this.req and this.res. This should answer your question, but it's undocumented/unsupported.
  • Thanks for your reply. Sadfully, this.req doesn't seem to be available as it's not defined.
  • You're right, I remember this was available in 0.8 maybe 0.9. Then I guess we're out of luck. You can open GitHub issue.
  • Emile has confirmed the possibility of getting the client's IP address will be added in the next update.
This discussion has been closed.