- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2022 11:25 AM
First let me say I am not a SNOW developer, but i am attempting to help update a bunch of our server CI records.
Currently on our Server CI records the "managed_by_group" field is blank. I'm working to populate them. once i can figure out how to do one, i can work the script to do what i need. I am formulating my body off of what i have done with other APIs. So maybe it's all wrong.
Also I am using Powershell. Any help would be great. End goal is to update cmdb_ci_server Record's managed_by_group field. Script is as follows....
$user = 'userName'
$pass = 'myPassword'
$table = 'cmdb_ci_server'
# 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')
$headers.Add('Content-Type','application/json')
# Specify endpoint uri
$uri = "https://myCompanyName.service-now.com/api/now/table/$($table)/02f625b41b002890710bed776e4bcb44"
# Specify HTTP method
$method = "PATCH"
# Specify request body
$body ='{"name":"managed_by_group","value":"8e21a6ea139ed600c86fbabed144b0d2"}'
# Send HTTP request
$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -Body $body
user i am using has admin. this is our sandbox.
Not only does this not work....it is actually deleting the server CI associated with the sys_ID at the end of the URI! Please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2022 11:31 AM
Hello Justin,
When using application/json content type, you should only need to pass the name:value as such: {"managed_by_group":"8e21a6ea139ed600c86fbabed144b0d2"}. See https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_TableAPI#table-PATCH
Please mark my answer as correct/helpful if it has helped you.
Thanks,
Logan
--
LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2022 11:31 AM
Hello Justin,
When using application/json content type, you should only need to pass the name:value as such: {"managed_by_group":"8e21a6ea139ed600c86fbabed144b0d2"}. See https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_TableAPI#table-PATCH
Please mark my answer as correct/helpful if it has helped you.
Thanks,
Logan
--
LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2022 01:18 PM
that was it. thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2022 01:26 PM
Hello Justin,
Glad to help and glad it was a simple fix!
Please mark my answer as correct/helpful if it has helped you.
Thanks,
Logan
--
LinkedIn