IBM QRadar SOAR

IBM QRadar SOAR

Join this online user group to communicate across Security product users and IBM experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  CALL REST API to ServiceNow using basic authentication error

    Posted Fri August 30, 2024 07:54 PM

    I am trying to use the CALL REST API function to query the ServiceNow CMDB CI but suck at the basic authentication issue. 
    I keep getting the 401 Client Error: Unauthorized error.

    Below is what I have in the "CALL REST API" function".    Any suggestions?

    import json
    headers = {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    }
    inputs.rest_api_method = 'GET'
    inputs.rest_api_headers = json.dumps(headers)
    inputs.rest_api_url = 'https://mycompany.service-now.com/api/now/table/cmdb_ci?sysparm_limit=1'
    inputs.rest_api_verify = False
    inputs.rest_api_body = 'auth=(myusrname, mysecretpassword)'



    ------------------------------
    Raymond Tam
    ------------------------------


  • 2.  RE: CALL REST API to ServiceNow using basic authentication error

    Posted Mon September 02, 2024 02:17 AM

    error says unauthorized so mostly the account you are using has no privileges to perform the action you are trying to do, elevate the account prives and try again.



    ------------------------------
    mohamad islam hamadieh
    ------------------------------



  • 3.  RE: CALL REST API to ServiceNow using basic authentication error
    Best Answer

    Posted Wed September 04, 2024 07:19 AM

    It looks like the issue is with how you are passing authentication details. For basic authentication in the CALL REST API function, you need to include the credentials in the headers.

    Here's how you can modify your code:

    python
    import base64 import json username = 'myusername' password = 'mysecretpassword' auth_string = f'{username}:{password}' auth_base64 = base64.b64encode(auth_string.encode()).decode() headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': f'Basic {auth_base64}' } inputs.rest_api_method = 'GET' inputs.rest_api_headers = json.dumps(headers) inputs.rest_api_url = 'https://mycompany.service-now.com/api/now/table/cmdb_ci?sysparm_limit=1' inputs.rest_api_verify = False inputs.rest_api_body = ''

    Make sure to replace myusername and mysecretpassword with your actual credentials. This should resolve the 401 Unauthorized error.



    ------------------------------
    Lee Stanton
    ------------------------------



  • 4.  RE: CALL REST API to ServiceNow using basic authentication error

    Posted Wed September 04, 2024 02:47 PM

    Thanks for the suggestions.  I verified the credential is good and has the permission.

    I just tried the suggested script, and it works.  I am able to authenticate successfully and got the API returned results.  Thanks a lot for the help.



    ------------------------------
    Raymond Tam
    ------------------------------