Search code examples
pythoncsvsoapwsdlservicenow

Downloading ServiceNow data into a CSV file using Python 3.5.2


Can someone please tell me how to use SOAP and WSDL functionality along with ServiceNow in order to download data into a CSV file. I'm using Anaconda version 3.5.2

A sample script would be really helpful

Downgrading is not an option for me.


Solution

  • I also had a requirement at my work to download and process a service-now report. You can do it either using SOAP , REST or WSDL. I am using REST. Not sure if that will help.

    You need to postfix download type after table name. For e.g. CSV in below example. Rest of the URL for report is same as you would download report manually from servicenow.

    Here is a working code that downloads a report in CSV format. Report URL and ID will need to be changed as per your organization.

    import requests
    import getpass
    
    
    url = "https://yourcompany.service-now.com/sys_report_template.do?CSV&jvar_report_id="1234567890abcdefg"
    
    uname=raw_input("Enter Username: ")
    pswd=getpass.getpass(prompt='Enter Password: ', stream=None)
    
    r=requests.get(url, auth=(uname, pswd))
    
    
    
    if r.status_code==requests.codes.ok:
        print("Requests made a connection.\n")
        f=open(r'C:\dump.csv', 'w')
        f.write(r.content)
        f.close()
    
    else:
        print("\nAn error occured while establishing a connection.")
        print("Status code returned: ",r.status_code)
    
    c=input("\nEnter a key to exit.\n")