Multiple Task SCTASK under single RITM- REST API

Nanasaheb
Kilo Contributor

I use Python Script to create tasks in multiple categories, 

now i need REST API url which help me to create more TASKS under one RITM/REQ.

anyone did this before?


update:
I have one ritm with one task is present but i want to add more  tasks under that RITM, any idea about it?

 

Thank You in advance

1 ACCEPTED SOLUTION

My bad. Need to also set "request_item". Change the line setting response to following.

 

    response = requests.post(url, auth=(SERVICENOW_USER, SERVICENOW_PWD), headers=headers,
                             data="{\"parent\":\"" + task.get('rtim')
                                  + "\",\"priority\":\"" + task.get('priority')
                                  + "\",\"state\":\"" + task.get('state')
                                  + "\",\"short_description\":\"" + task.get('short_description')
                                  + "\",\"request_item\":\"" + task.get('rtim')
                                  + "\",\"assignment_group\":\"" + task.get('assignment_group') + "\"}")

Output

find_real_file.png

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Nanasaheb 

you need to use REST API explorer for this

Specify the Request Item and other fields such as short description, assignment group etc

Regards
Ankur

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

Hi Ankur,

Actually i dont have REST API Explorer access so i am trying at my own level.

i asked Admin team to get this API url, they have access but they dont know how to do it.

if you know steps then let me know, ill ask them to do same from their end.

 

Thank You!!

Hitoshi Ozawa
Giga Sage
Giga Sage

Following will add a task to rtim.

import requests

SERVICENOW_INSTANCE = '<ServiceNow instance>'
SERVICENOW_USER = '<username>'
SERVICENOW_PWD = '<password>'


def insert_new_task_2_rtim(task):
    url = f'https://{SERVICENOW_INSTANCE}.service-now.com/api/now/table/sc_task'
    headers = {"Content-Type": "application/json", "Accept": "application/json"}
    response = requests.post(url, auth=(SERVICENOW_USER, SERVICENOW_PWD), headers=headers,
                             data="{\"parent\":\"" + task.get('rtim') + "\",\"priority\":\"" + task.get('priority') + "\",\"state\":\"" + task.get('state') + "\",\"short_description\":\"" + task.get('short_description') + "\",\"assignment_group\":\"" + task.get('assignment_group') + "\"}")

    if response.status_code != 200:
        print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:', response.json())
        exit()

    data = response.json()
    print(data)


if __name__ == '__main__':
    task = {'rtim': 'ab10cc9fdbef901083212a9a48961929',
            'priority': '4',
            'state': '1',
            'short_description': 'test task',
            'assignment_group': '8a4dde73c6112278017a6a4baf547aa7'
            }
    insert_new_task_2_rtim(task)

 

I tried, this creates task but not associating with passed RITM. RITM field shows  empty.

passed different variables information but same output i got.


any idea why this is happening, same thing i tried before that time it was creating Request, RITM and task for each api call.