Powershell Service-NOW REST API: How to fetch a particular request item with RITM number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2018 05:18 AM
I know that "sys_id" can be used to fetch a requested item. But what if I don't have a sys_id? Since only the number is visible on the service now console.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2018 01:05 PM
Hi There,
Very simple.
try the below code and it should work.
var gr = new GlideRecord("sc_req_item");
gr.get("number","RITM00011323");
gs.print(gr.sys_id);
Just change the RITM number with your number and you should be good.
Best Regards,
Rahul
Please mark this post correct if it resolved your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2018 08:27 PM
Hi Rahul,
Thank you for your reply. I was actually looking for something in powershell. The snippet you've provided looks like javascript.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2019 08:34 AM
Hello,
I don't know if this might help you or you have already received your answer by now. But, anyways if this helps 🙂
(Sys_id of the RITM)
# Eg. User name="admin", Password="admin" for this code sample.
$user = "admin"
$pass = "admin"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
# Specify endpoint uri
$uri = "https://honeywelltest.service-now.com/api/now/table/sc_req_item/a21cb9aedbc4089031e0e665059619e6"
# Specify HTTP method
$method = "get"
{request.body ? "$body = \"" :""}}
# Send HTTP request
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri
# Print response
$response.RawContent
Thanks,
Ak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2019 08:37 AM
Hello,
Not sure if this might completely help you or you might have already got the solution as of now. But, anyways here it is.
# Eg. User name="admin", Password="admin" for this code sample.
$user = "admin"
$pass = "admin"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
# Specify endpoint uri
$uri = "https://yourinstance.service-now.com/api/now/table/sc_req_item/{sys_id of RITM}“
# Specify HTTP method
$method = "get"
{request.body ? "$body = \"" :""}}
# Send HTTP request
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri
# Print response
$response.RawContent
Thanks,
Ak