How to know the sender's hostname for an inbound API request

TT3
Kilo Guru

We have an inbound API setup, multiple systems are calling the same API. We need to know who was the sender for the API (we can't create separate user account for them). Is there anything in the log?

For example, SNOW instance have an inbound API and Yahoo is sending some data and then Google is sending some data. How can we figure out that which call was from Yahoo and which one was from Google?

Thank you.

1 ACCEPTED SOLUTION

Frank Tate
Giga Guru

By default, this information isn't logged by ServiceNow. You can capture it by turning on REST API debugging (system property: glide.rest.debug), but that's not recommended in production.

I'm assuming you're dealing with Scripted REST API. If this is the case, what I would do is get the source IP address using:

var sourceIp = request.headers["x-forwarded-for"];

And then store that IP address somewhere in the record or logging it with gs.log()

NOTE: This only gets the IP address, not the hostname.

Frank

Please mark this reply as Helpful/Correct if you find it helpful.

View solution in original post

1 REPLY 1

Frank Tate
Giga Guru

By default, this information isn't logged by ServiceNow. You can capture it by turning on REST API debugging (system property: glide.rest.debug), but that's not recommended in production.

I'm assuming you're dealing with Scripted REST API. If this is the case, what I would do is get the source IP address using:

var sourceIp = request.headers["x-forwarded-for"];

And then store that IP address somewhere in the record or logging it with gs.log()

NOTE: This only gets the IP address, not the hostname.

Frank

Please mark this reply as Helpful/Correct if you find it helpful.