The CreatorCon Call for Content is officially open! Get started here.

Powershell Service-NOW REST API: How to fetch a particular request item with RITM number?

PowerShellSingh
Kilo Explorer

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.

4 REPLIES 4

Rahul Shandily3
Giga Guru

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.

Hi Rahul,

Thank you for your reply. I was actually looking for something in powershell. The snippet you've provided looks like javascript.

 

akonisetty
Kilo Explorer

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

akonisetty
Kilo Explorer

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