Hi All
We have many Names and Strings with '&' and it looks like that DVLS cannot handle this when using /api/connection/save (doesnt matters in which field).
In My Case i want to change "CredentialPrivateVaultSearchString" in ConnectionData.Connection.
When the String Contains '&' then it failes with "Object reference not set to an instance of an object." If i replace '&' with '+' it works. But '&' is needed for correct Informations.
Invoke-WebRequest -Uri "$Global:dvlsBaseUrl/api/connection/save" -Method "PUT" -Body $jsonBody -ContentType "application/json; charset=utf-8" -WebSession $Global:WebSession
DVLS Module: Most current Git Release (2022.2.6.1 with all additional Commits)
DVLS Server: v2022.2.6.0
PS: 7.2.6
Best Regards,
Andreas
Hi Andreas,
Thank you for reporting this problem. We will investigate and get back to you shortly.
Best regards,
Érica Poirier
Hi Andreas,
Everything works as expected on my end. Could you please provide more information and/or the script you are trying to execute so that I can further assist you?
Best regards,
Alexandre Martigny
Hey Alex
Im sorry for the late response.
Here is one Example:
Im trying to update a Folder's credential settings. Goal: Adding CredentialConnectionID and CredentialPrivateVaultSearchString, which contains the Vault's Name with &
# load folder details $folder = (Get-DSEntry -EntryId $folderId -AsRDMConnection).Body.data.connectionInfo # convert data from xml to object $ConnectionData = Convert-XMLToPSCustomObject ([xml]$folder.Data) $ConnectionMetaData = Convert-XMLToPSCustomObject ([xml]$folder.metaDataString) # set parameters $ConnectionData.Connection | Add-Member -NotePropertyName 'CredentialConnectionID' -NotePropertyValue "88E4BE76-4C5B-4694-AA9C-D53B7E0FE0DC" -Force $ConnectionData.Connection | Add-Member -NotePropertyName 'CredentialPrivateVaultSearchString' -NotePropertyValue $Customer -Force # rebuild xml structure $ConnectionDataXML = New-XMLfromObject -object $ConnectionData.Connection # $ConnectionMetaDataXML = New-XMLfromObject -object $ConnectionMetaData.ConnectionMetaDataEntity -RootName 'ConnectionMetaDataEntity' $ConnectionMetaDataXML = Convert-PSCustomObjectToXML $ConnectionMetaData.ConnectionMetaDataEntity -RootName 'ConnectionMetaDataEntity' # set parameters $folder | Add-Member -NotePropertyName 'data' -NotePropertyValue $ConnectionDataXML -Force $folder | Add-Member -NotePropertyName 'metaDataString' -NotePropertyValue $ConnectionMetaDataXML.outerXML -Force $jsonBody = ConvertTo-Json ($folder) -Depth 6 $response = Invoke-WebRequest -Uri "$Global:dvlsBaseUrl/api/connection/save" -Method "PUT" -Body $jsonBody -ContentType "application/json; charset=utf-8" -WebSession $Global:WebSession
$ConnectionDataXML in the example above which fails contains:
<?xml version="1.0"?>
<Connection>
<ConnectionSubType>Folder</ConnectionSubType>
<ConnectionType>Group</ConnectionType>
<CreatedBy>d2a11ddf-4dd2-49e9-a336-bd785c69bd26</CreatedBy>
<CreationDateTime>2022-08-26T10:13:32</CreationDateTime>
<DisplayMonitor>Primary</DisplayMonitor>
<Group>2. Sessions</Group>
<ID>f98404fe-a145-4e32-94b1-02eec862f5dd</ID>
<ImageName>SampleSessionBlue</ImageName>
<Name>2. Sessions</Name>
<Security>
<Permissions></Permissions>
<RoleOverride>Custom</RoleOverride>
</Security>
<Stamp>8a41afa9-5dc5-4958-8fc9-db7260b4873d</Stamp>
<Status>{B299F468-BC24-43cb-9417-4FEDFC813E7C}</Status>
<UpdateDateTime>2022-08-31T07:16:43</UpdateDateTime>
<CredentialConnectionID>88E4BE76-4C5B-4694-AA9C-D53B7E0FE0DC</CredentialConnectionID>
<CredentialPrivateVaultSearchString>Name with & within</CredentialPrivateVaultSearchString>
</Connection>
This returns "Object reference not set to an instance of an object."
When im changing $Customer to a Value without & within, everything works as expected. It also works by using $Customer.replace("&", "") but then the Name isnt correct anymore.
Best Regards,
Andreas
Hi Andreas,
Just a reminder that fetching an entry as a RDM connection and converting from and to XML is only necessary when trying to create or update an entry that has yet to be supported in DVLS. In this case, it is not necessary since you are trying to update a folder.
I have successfully updated a folder's credential to a private vault search including ampersand using the following code;
#Fetch folder
$Folder = (Get-DSEntry -EntryId $FolderID).Body.data
#Handle folder's path...
$Folder.group = $Folder.group.Substring(0, $Folder.group.LastIndexOf('\'))
#... or if folder's at root
$Folder.group = ''
#Change credential mode, add credentialConnectionId, add privateVaultSearchString
$Folder.data | Add-Member -NotePropertyName 'credentialMode' -NotePropertyValue ([CredentialSourceMode]::PrivateVaultSearch) -Force
$Folder.data | Add-Member -NotePropertyName 'credentialConnectionId' -NotePropertyValue $CredentialConnectionId -Force
$Folder.data | Add-Member -NotePropertyName 'privateVaultSearchString' -NotePropertyValue "Ampersand&test&" -Force
#Save updated folder
$ServerResponse = (Update-DSEntryBase -jsonBody (ConvertTo-Json $Folder -Depth 10)).Body.data
As you can see from above, I added code to handle the folder's path. This is necessary when updating a folder in order to keep the correct path once saved.
For future reference, if you need to include an ampersand in any string when creating or updating an unsupported entry (converting from and to XML), you need to escape them like this;
"Ampersand&test&"
Best regards,
Alexandre Martigny
Thanks Alex, that worked!
Best Regards
Andreas