Viewing Assets from External Portal Returns a 500 Error
Closed this issue · 5 comments
Hello,
I get a 500 error when creating or updating assets using the HuduAPI module, adding it to the company's External Portal, and then trying to view it from said portal.
The only way I've found to fix it is to edit the asset in the internal assets via the web dashboard and click the update button.
Is this a known bug?
Please let me know if you need any more information.
Thank you in advance and for making a great tool for connecting to the Hudu API.
Hudu support had said this about a month ago when I asked:
This "500 error" is 100 percent stemming from Luke Whitelock's script after testing. My best accurate guess would be that there's something corrupted with the way that script is handling "Asset Link Fields". When I tested I had no issues sharing assets to any company's "External Portal" that had an "Asset Link" field.
I realize now that this 500 error doesn't happen when I don't try to have a "Site" location asset or link to any asset for that matter.
The error when I use AssetTag, which is what the Hudu support told me to use to link to an Asset.
I started with this integration with TacticalRMM: https://github.com/bc24fl/tacticalrmm-scripts/blob/main/Tactical_Hudu_Sync.ps1
And made quite a lot of changes: https://github.com/ZzBombardierzZ/tacticalrmm-scripts/blob/main/Tactical_Hudu_Sync.ps1
Please let me know if I'm linking to Assets wrong or if there's anything I can do to fix this issue while still linking to an Asset.
Hey @ZzBombardierzZ this is actually a bug in the function but if you're using valid, properly cased field types it shouldn't cause an issue with the asset layout itself.
I'll be pushing a new version shortly that will include a revised version of the validation that should work.
Hi @greenlighttec, I appreciate the fast response and the new update. The error in PowerShell is no longer there. However, I still get a 500 error when the asset has a linked asset to it. I could be doing something wrong on my end, but I'd greatly appreciate any advice.
You can see the code I'm running here: https://github.com/ZzBombardierzZ/tacticalrmm-scripts/blob/main/Tactical_Hudu_Sync.ps1
My only idea is that maybe I'm getting the linked asset to link to incorrectly?
Thanks,
Likely the value you're populating the site with is invalid, it needs to be a JSON array string with a very specific makeup. Here's an example of what I've done in some of my scripts.
$ConnectedNetworkTagString = [pscustomobject]@{id = $ConnectedNetwork.id; url = "/a/$($ConnectedNetwork.slug)"; name = $ConnectedNetwork.name}
connected_network = $ConnectedNetworkTagString|ConvertTo-Json -Compress -AsArray
@greenlighttec Thank you so much! Adding -Compress -AsArray
to this line $siteToLinkJson = $siteToLinkArray | ConvertTo-Json
did in fact fix it for me.
Thanks!