Getting an error while trying to pull the data from ServiceNow into my React App using REST API

Chandra Mouli
Tera Contributor

Hi Team,

I am trying to connect ServiceNow platform to my React app using REST API. However, I am getting error message.

Below is the piece of code for reference:

Note: I have tested the API using "Postman" and it is working fine without any issues(Credentials are correct).

 

const Fetchincidentdata = useCallback(async () => {
    try {
      const username = "****";
      const password = "******";

      const response = await fetch(url, {
        mode: "no-cors",
        method: "GET",
        headers: {
          Authorization: "Basic" + btoa(username + ":" + password),
          //'Accept': "application/json",
          "Content-Type": "application/json",
        },
      });

      const data = await response.json();
 
Attached the error screenshot for reference:
 
Please check and help.
 
Thanks,
Mouli
6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Chandra Mouli 

can you share how you configured the REST message in ServiceNow?

Also share the scripts and screenshots.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

Thanks for responding.

 

I didn't configured any REST message. I am using "REST API Explorer" for checking the connectivity.

I tried with the API that is created upon clicking "Send".

Note: Able to fetch the data using Postman..

Please let me know if you need any further details.

 

Thankyou,

@Chandra Mouli 

the error is http 401 -> meaning wrong user name and password combination

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

I have used the same credentials in postman and it is working as expected.