You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Updating an NPrinting filter using "Invoke-NPRequest -method Put -Path "filters/$filterId" -Data $filter" goes wrong in the situation where the filter represents a body coming as a response from Invoke-NPRequest -method Get -Path 'filters' and the filter contains at least one field value. This is due to an issue of unwanted data loss with powershell's ConvertTo-Json cmdlet:
The default -Depth of this cmdlet has the value 2, and if the object you're converting is deeper than this, the result is data loss. In the case of a filter with at least one field value, the "values" attribute of the fields becomes an empty string instead of an array.
To Reproduce
Try to update a filter description which has at least one field value by first fetching the body using Invoke-NPRequest -method Get -Path 'filters', slightly modify the description, and then "Invoke-NPRequest -method Put -Path "filters/$filterId" -Data $filter" . You should run into a HTTP 400 Bad Request error.
Expected behavior
I'd expect a body retrieved by Invoke-NPRequest -method Get -Path 'filters' to by default be usable in a PUT-request, but the ConvertTo-Json cmdlet breaks the body. I advise changing every call to ConvertTo-Json in the Invoke-NPRequest implementation to include the -Depth option with a value of 100 or so.
Environment:
OS: Windows Server
PowerShell Version 5.1.14393.5066
Nprint Version May21
The text was updated successfully, but these errors were encountered:
I agree that this works, and I thank you for your fast feedback! However, I consider this to be a workaround. I would still suggest changing it within the module itself. My argument for doing so: If the module itself supports converting from Powershell internal structures to the expected Json structure by the NPrinting API, it would be nice if it always works and not sometimes result in the content being destroyed.
I must admit that I really struggled a bit in figuring out this issue. I had to change my local version of the module to write out the body that's being put in the HTTP Request before I saw that the array was suddenly missing. The NPrinting API also doesn't help much by simply returning a HTTP 400 error without further details. I can imagine that should the usage of NPrinting increase, and by consequence also the usage of this module, other people will also be confronted by this issue and pull their hair out.
Just in general I think it should be the the goal that any item retrieved by the Get should be valid as input for the Put calls, as this makes Development in many cases much easier. I've seen sometimes that NPrinting itself isn't compliant with this logic (changing connections for example in my experience), but in this case it's the module that's breaking the content.
Regardless of this issue I wish to thank you for making this module publicly available, as it will really accelerate our automation goals concerning templatized report generation using Qlik Sense / NPrinting.
Describe the bug
Updating an NPrinting filter using "Invoke-NPRequest -method Put -Path "filters/$filterId" -Data $filter" goes wrong in the situation where the filter represents a body coming as a response from Invoke-NPRequest -method Get -Path 'filters' and the filter contains at least one field value. This is due to an issue of unwanted data loss with powershell's ConvertTo-Json cmdlet:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7.2
The default -Depth of this cmdlet has the value 2, and if the object you're converting is deeper than this, the result is data loss. In the case of a filter with at least one field value, the "values" attribute of the fields becomes an empty string instead of an array.
To Reproduce
Try to update a filter description which has at least one field value by first fetching the body using Invoke-NPRequest -method Get -Path 'filters', slightly modify the description, and then "Invoke-NPRequest -method Put -Path "filters/$filterId" -Data $filter" . You should run into a HTTP 400 Bad Request error.
Expected behavior
I'd expect a body retrieved by Invoke-NPRequest -method Get -Path 'filters' to by default be usable in a PUT-request, but the ConvertTo-Json cmdlet breaks the body. I advise changing every call to ConvertTo-Json in the Invoke-NPRequest implementation to include the -Depth option with a value of 100 or so.
Environment:
The text was updated successfully, but these errors were encountered: