trying to call ServiceNow table REST API from SharePoint Framework (SPFx) with basic authentication with correct credentials and still getting 401 unauthorized error

Seshavalli Pull
Giga Contributor

trying to call ServiceNow table REST API from SharePoint Framework (SPFx) with basic authentication with correct credentials and still getting 401 unauthorized error

I tried calling the service now rest api from postman and its working with out any issues.

find_real_file.png

however if I tried same calling from SharePoint framework (SPFx), getting 401 UNAUTHORIZED error

find_real_file.png

please let me know how to solve this issue

2 REPLIES 2

Mahak2
Kilo Guru

Hello,

 

Can you please check if the integration user has right set of roles like rest_service,itil etc in order to access the Incident table?

 

Please let me know after checking.

 

Thanks

Seshavalli Pull
Giga Contributor

I am using Admin role user in basic authentication and with same user, its working in postman and same is not working in SharePoint Framework (SPFx).

Note: I am also converting the credential as Base64 and passing to headers as below

var credBase64 = btoa(user + ':' + password);

        const requestHeaders: Headers = new Headers();
        requestHeaders.append('Content-type', 'application/json');
        requestHeaders.append('Accept', 'application/json');
       
        requestHeaders.append('Access-Control-Allow-Origin', '*');
        requestHeaders.append('Authorization', 'Basic' + credBase64);
 
const httpClientOptions: IHttpClientOptions = {
          headers: requestHeaders,
          method: 'GET',
          mode: 'no-cors',
        };
 
this._httpClient
          .get(
            'https://devinstance.service-now.com/api/now/table/incident?',
            HttpClient.configurations.v1,
            httpClientOptions
          )
          .then((response: HttpClientResponse) => {
            debugger;
            console.log('Response Object: ' + response.json());
            return response.json();
          })
          .then((responseJSON: ServiceNowTicketEntity) => {
            debugger;
            console.log('Response Object 1: ' + responseJSON);
            console.log(responseJSON);

            //return responseJSON.title;
            resolve(responseJSON);
          });