Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Servicenow Table API
#1
Good Afternoon,

I need to write python code to get last 5 days of data from ServiceNow Table API for example sc_req_item table. can anyone help me to build the method with headers, parameters and response.
Reply
#2
Welcome to the forum. We are glad to help, but we are not going to write code for you.
There is nice documentation with python examples. So it's a good place to start.
Write some code and when you face problem - come here and ask specific question. Always post your code in python tags, full traceback (if any) - in error tags.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Here is my method: I have two tasks now
1. i need to pass delta_dt some where to get last five days of data by sys_updated_on
2. i need to write if condition to go for loadtype as full or incremental. In incremental i need to get last 5 days of data.
def call_api_get_total_record_count(url, username, password, loadtype):
    delta_dt = (date.today() - timedelta(days=5)).isoformat()
    headers = {"Content-Type": "application/json", "Accept": "application/json"}
    parameters_full = {"sysparm_limit": "1"}
    parameters_incremental = {"sysparm_limit": "1", "sysparm_query": "sys_updated_on"}
    response = requests.get(url, auth=(username, password), headers=headers, params=parameters)
    totalrecordcount = int(response.headers['X-Total-Count'])
    return totalrecordcount
this code is to retrieve total count of rows either for full load or last 5 days of incremental load
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020