itglue / powershellwrapper

This PowerShell module acts as a wrapper for the IT Glue API.
Apache License 2.0
120 stars 51 forks source link

New-ITGlueFlexibleAssets can't find route for bulk add #144

Closed LastElf closed 1 year ago

LastElf commented 2 years ago

Steps to reproduce

Seems to be the same as #92 I have a System.Collections.Generic.List object with two flexible assets in it. Using the conversion depth I get this output:

[ { "type": "flexible-assets", "attributes": { "flexible_asset_type_id": <obsf>, "traits": { "trait1": value1, "trait2": "value2" }, "organization_id": <obsf> } }, { "type": "flexible-assets", "attributes": { "flexible_asset_type_id": <obsf>, "traits": { "trait1": value1, "trait2": "value2" }, "organization_id": <obsf> } } ]

I pass this through with New-ITGlueFlexibleAssets -data $list

Expected behavior

New objects get created

Actual behavior

Returns error: New-ITGlueFlexibleAssets: {"errors":[{"status":422,"title":"bulk action not allowed for Flexible Asset using this route","source":{"pointer":"data"}}]}

Using this with the exact same list does work, but makes too many API calls for my liking: foreach ($object in $list) {New-ITGlueFlexibleAssets -data $object}

I have also tried @($list[0],$list[1]) just to sanity check it isn't something weird with the List type.

Environment

Please share additional details about your environment. Version information for:

davidhaymond commented 1 year ago

@LastElf To use the flexible asset bulk creation route, you must provide the organization ID:

New-ITGlueFlexibleAssets -data $list -organization_id 12345

The API does not support creating flexible assets from different organizations in one API call; you must call the API once per organization.