The CreatorCon Call for Content is officially open! Get started here.

REST Message Problem

Ken83
Mega Guru

Hello Community,

        My goal with this REST message is to retrieve some information from another system that resides on my local domain. We do not have any domain separation or anything like that configured on our SN instance. I just need SN to reach out via REST to System B and retrieve some information. Sounds simple enough but the problem I am having is a 401 error. Like this...

find_real_file.png

Now, to me this seems like a very straightforward problem. I'm not successfully authenticating somewhere. My question is...WHERE??? I have removed the requirement for Basic Authentication so AFAIK, there aren't any credentials being passed in the message. To get to this point, I did route the message through a MID Server I have setup on my instance. I am aware that the MID Server requires credentials to do whatever it does. In light of this, I even replaced the MID Server credentials with my credentials because I know I have access to System B. I have logged into System B successfully multiple times.

The other trickery here is that while I am getting this 401 error message when using a REST message in SN, if I copy the endpoint and paste it directly into my browser, it shows me the information I am expecting to see...See below..

find_real_file.png

So my question is, how can I track down this authentication problem? When I try this from SN, I get the 401 error. When I paste the endpoint directly to the browser, I get the success message above.

1 ACCEPTED SOLUTION

venkatiyer1
Giga Guru

Hi ken,



In your endpoint you can remove ?apikey=${apikey} and just have till servicegroups. Since you are already passing that message function parameter. Rest of the configuration looks good to me. Also, in the endpoint i..e servicegroups, what kind of content type is being served. Is it html or json? You might want to check the endpoint to see if it html. If so you might have to add that as accept type rather than json.  


View solution in original post

10 REPLIES 10

Chuck Tomasi
Tera Patron

Hi Kenneth,



The client (in this case it looks like a PHP app) needs to provide the credentials to ServiceNow. This can be done with an Authentication header. If you prototype this using the REST API Explorer and the credentials you wish to use, you can get the header and the value for your app.



The reason it is working from your browser is because you are already authenticated (and it remembers your session.)


Fair enough, I added an Authorization header to the REST Message - GET method - using my credentials(which apparently get base64 encoded so it looks weird) but when I run the tests, I still get 401 not authorized. So let me back track for a minute to make sure I've dotted my t's and crossed my i's(yes....i know)..



My Message Headers...


find_real_file.png



My Message Functions...


find_real_file.png



Am I missing anything here?


Hi Kenneth,



I thought ServiceNow was the provider/producer and the PHP app was the client/consumer? If that's the case, the PHP app needs to send the header information to ServiceNow. What you've shown here is ServiceNow's header information (for an outbound REST request from someone else.) Did I get this backwards?


Actually, I think you hit the hail on the ned, 'tis I who has forgotten my App Dev homework and gotten confused between the provider and consumer of the service. So, ServiceNow is actually consuming(client/consumer) the service from System B.