itglue / automation

A place for IT Glue's user community to learn ways of automating their documentation.
Apache License 2.0
99 stars 33 forks source link

401,"title":"Unauthorized" #31

Closed sebastiaan-levix closed 4 years ago

sebastiaan-levix commented 4 years ago

Hi,

I've got the AD automation working and also the File Share is working for me. Now I'd like to create some customizing based on the script but it all seems to be very exact in the coding. ITGlue returns 401 Unauthorized resource access pointer":"id"

I've created a basic test script

`function formatAPIData {

$api__body = @{
    type = "flexible_assets"
    attributes = @{
        "organization-id" = '1694461951918297'
        "flexible-asset-type-id" = '1708673018626277'
        traits = @{
            "share-name" = 'test'
            "share-description" = 'description'
            "servers" = ''
            "share-path" = 'test'
            "disk-path" = 'C:\testpath\TEST\test'
            "share-permissions" = 'test'
        }
    }
}

return $api__body

}

try { Import-Module ITGlueAPI } catch { Write-Error "ERROR: The IT Glue API PowerShell module cannot be imported." Write-Error "Please download it from https://github.com/itglue/powershellwrapper, configure it, and try again." }

$api__body = formatAPIData # format data for API call

Write-Host "Creating a new flexible asset."

$api__body.attributes
$api__body.attributes.traits

$api__output_data = New-ITGlueFlexibleAssets -data $api__body -verbose`

Running this script returns powershell_ITGLUE_401

When I compare $apibody.attributes and $apibody.attributes.traits to the file share script they are exactly the same. What does this 401 error pointer":"id" mean and how to fix it?

thanks in advance, Sebastiaan

sebastiaan-levix commented 4 years ago

Got a little further, it's the tagged item servers that is giving the error. Commenting the tagged field wil upload the data to IT Glue.

How do I send a tagged item?

sebastiaan-levix commented 4 years ago

found it

$apiorg_id = '1694461951918297' $api__Server_id = (Get-ITGlueConfigurations -filter_organization_id $apiorg_id -filter_name WIN-AQL6UQ6JPKO).data.id

traits = @{ "share-name" = 'test' "share-description" = 'description' "servers" = $api__Server_id "share-path" = 'test' "disk-path" = 'C:\testpath\TEST\test' "share-permissions" = 'test' }

And also good to know is that Capital letters are not aloud in traits.

Hope this treat wil help others.