Hello,
I am running into a wall trying to update a custom_fields_values field using powershell.
Using a test account as an example, when I pull that information from the API i get:
id : 1825771
name : Raymond O'Brien
disabled : False
title : Test Account
email : stuobrienr@wcsu.edu
created_at : 2016-09-22T14:40:36.000-04:00
updated_at : 2022-02-17T16:28:38.000-05:00
last_login : 2019-07-19T13:37:06.000-04:00
phone :
mobile_phone : 1-555-555-5555
role : @{id=268839; name=Requester; description=Requester role to view and submit service request.; portal=True; show_my_tasks=False}
salt : 8534d97862fd0664940d6ddbf6fa46e40e98e23a
group_ids : {2027487}
available_for_assignment : False
can_be_available_for_assignment : False
custom_fields_values : {@{id=25664696; custom_field_id=30358; name=Building/Room/Loc; value=OM 303; attachment=; options=; type=1; type_name=Text; entity=; user=}}
site : @{id=50125; name=WCSU; location=Danbury, CT; description=Western Connecticut State University; time_zone=Eastern Time (US & Canada); language=en;
business_record=}
department :
avatar : @{type=initials; initials=RO; color=#dfcd00}
reports_to :
I don't have an issue updating fields like the title.
However, when I try to update a custom field we created, I run into all sorts of brick walls.
What I am trying to do is take the office location value from our AD and I want to insert that location into the custom field we created on SWSD.
As you can see from the output, custom_fields_values is layered.
I am trying to change the value of "value" within the the custom_fields_values. I cannot seem to get it right. I feel like I am getting close.
Below is a good chunk of my code.
If anyone call give me some tips on how to properly update it, I would appreciate it.
Code below:
$JsonWebToken =
$Headers = @{ "X-Samanage-Authorization" = "Bearer $JsonWebToken";
"Accept" = "application/vnd.samanage.v2.1+json"
"Content-Type" = "application/json" }
$URI = "">api.samanage.com/.../1825771.json"
$SWSDUser = Invoke-RestMethod -Method Get -Headers $Headers -Uri $URI
$SWSDUserID = $SWSDUser.id
$SWSDTargetUserEmail = $SWSDUser.email #Selects email address of target user on Solarwinds Service Desk
$SWSDTargetUser = $SWSDTargetUserEmail.TrimEnd("@wcsu.edu") #Trims off email ending so we remain with just the username
$TargetADUSEROffice = get-aduser -Identity $SWSDTargetUser -Properties * | select-object -ExpandProperty Office #Selects the Office location currently on Active Directory
$CustomFieldName = 'Building/Room/Loc'
$SWSDUploadUser = @{user=@{}}
$SWSDUploadUser.user['id'] = $SWSDUserID
$SWSDUploadUser.user['custom_fields_values'] = @{}
$SWSDUploadUser.user.custom_fields_values['name'] = $CustomFieldName.tostring()
$SWSDUploadUser.user.custom_fields_values['value'] = $TargetADUSEROffice.tostring()
Invoke-RestMethod -Method Put -Headers $Headers -Uri "">api.samanage.com/.../$($SWSDUserID).json" -Body (convertto-json $SWSDUploadUser)
I keep getting the error below:
"Invoke-RestMethod: {"error":["The property '#/user/custom_fields_values' of type object did not match any of the required schemas. The schema specific errors were:\n\n- oneOf #0:\n - The property '#/user/custom_fields_values' did not contain a required property of 'custom_fields_value'\n- oneOf #1:\n - The property '#/user/custom_fields_values' of type object did not match one or more of the following types: string, null"]}"
Thank you in advance for any assistance!