How to request approval in change request through API?

DanoneTech
Giga Contributor

Hello, All.
I know this question already has been asked before, but I didn't find the correct answer or the solution is not working as expecting.

I'm trying to push "Request Approval" button on standard change request (see screenshot) through API or in other words move change request to "Autorize" state. Doing some web scraping I found the exact ID of the UI action of this button. Here's the code in Powershell:

 

$Params = @{
    Headers = $GlobalHeaders
    Method = "Post"
    Body = @{
        fields = @(@{
            name = ""
        })
    } | ConvertTo-Json
    Uri = "$ServiceNowSandboxInstance/api/now/ui/ui_action/f07eedb3cb200200d71cb9c0c24c9c3d?sysparm_table=change_request&sysparm_sys_id=[change_sys_id]&api=api"
}

Invoke-RestMethod @Params

The output shows status code: 201 (Created). But nothing happens to the change request.

Am I missing something or maybe there is another way to do this?

1 REPLY 1

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

The OOTB 'Request approval' UI action with the above sys_id is using client side code, but there is no user session, hence client side APIs like g_form would not work.

I would rather set-up a scripred Rest API and call that - you can then have the server-side equivalent of the UI action run in that custom scripted api.