automation icon indicating copy to clipboard operation
automation copied to clipboard

Does not upload to ITGlue because the following error.

Open MartinRiley opened this issue 7 years ago • 12 comments

Invoke-RestMethod : {"errors":[{"status":401,"title":"Unauthorized","detail":"Unauthorized resource access","source":{"pointer":"id"}}]} At C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI\Resources\FlexibleAssets.ps1:12 char:20

  • $rest_output = Invoke-RestMethod -method "POST" -uri ($ITGlue_Base_URI + $re ...
    
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
     eption
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    
    

for what i can see it looks like i did not put in the correct Uri?? But we dont use a gateway or anything so in my eyes it has to be the default uri?

other then that it seems because of the "Unauthorized resource access" that i dont have access to my own ITGlue.

an other problem that keep occuring and this might be relevant is that as soon as i type in Get-ITGlueAPIKey it doesent show me my apikey even with the Force command.

PS C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI> Get-ITGlueAPIKey System.Security.SecureString Use Get-ITGlueAPIKey -Force to retrieve the unencrypted copy. PS C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI> Get-ITGlueAPIKey -Force System.Security.SecureString Use Get-ITGlueAPIKey -Force to retrieve the unencrypted copy. PS C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI> .\ActiveDirectory.ps1 -api api_config-ActiveDirectory.psd1

So if anyone can help me with what im doing wrong let me know thx :)

MartinRiley avatar Jan 03 '18 13:01 MartinRiley

I'm having the same issue, any fix for this yet?

taylormaguire avatar Jan 20 '18 23:01 taylormaguire

Hey MartinRiley,

Pardon the delay in response, I have been out of state for a while now and am catching up.

Would you be able to run Get-ITGlueBaseURI? If you are using IT Glue's API without any proxies or other more advanced use cases, you should just get http://api.itglue.com as the output. If you do not, please run Add-ITGlueBaseURI without parameters to make it default to the http://api.itglue.com address.

If you are still getting an error, I would suggest re-adding your API key. Afterwards, it is advantageous to run Export-ITGlueModuleSettings so that the working URI and API key are auto-imported when you load the module.

As for the Get-ITGlueAPIKey, it will not return the unencrypted API key even with the -Force parameter as a security measure, as your API key is able to access all IT Glue data across all organizations, which can be somewhat dangerous if given in plaintext. As such, it returns an object that contains the encrypted version. The -Force option is depreciated and I appreciate you bringing it to my attention, as it was meant to be removed.

You are able to unencrypted your API key if you so desire by running (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password), which is a PowerShell cmdlet built for managing SecureStrings. It uses reversible encryption tied to your user principle (user account on your specific Windows device).

Please let me know if setting the Base URI to the default works. If not, let's run Get-ITGlueUsers or some other command to test that the module is set up properly before continuing on with the ActiveDirectory script troubleshooting.

CalebAlbers avatar Jan 21 '18 02:01 CalebAlbers

well caleb just sent me a msg i will check in 2 days if it works i will let you know


Van: taylormaguire [email protected] Verzonden: zondag 21 januari 2018 0:41 Aan: itglue/automation CC: MartinRiley; Author Onderwerp: Re: [itglue/automation] Does not upload to ITGlue because the following error. (#4)

I'm having the same issue, any fix for this yet?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/itglue/automation/issues/4#issuecomment-359211038, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AhcWTZ5VeSUTYnYCGxbIgbLvr-YqaSRGks5tMnmcgaJpZM4RRulT.

MartinRiley avatar Jan 21 '18 18:01 MartinRiley

Np thx for replaying i will check tuesday when im back at work and then i will let you know 😊


Van: Caleb Albers [email protected] Verzonden: zondag 21 januari 2018 3:02 Aan: itglue/automation CC: MartinRiley; Author Onderwerp: Re: [itglue/automation] Does not upload to ITGlue because the following error. (#4)

Hey MartinRiley,

Pardon the delay in response, I have been out of state for a while now and am catching up.

Would you be able to run Get-ITGlueBaseURI? If you are using IT Glue's API without any proxies or other more advanced use cases, you should just get http://api.itglue.com as the output. If you do not, please run Add-ITGlueBaseURI without parameters to make it default to the http://api.itglue.com address.

If you are still getting an error, I would suggest re-adding your API key. Afterwards, it is advantageous to run Export-ITGlueModuleSettings so that the working URI and API key are auto-imported when you load the module.

As for the Get-ITGlueAPIKey, it will not return the unencrypted API key even with the -Force parameter as a security measure, as your API key is able to access all IT Glue data across all organizations, which can be somewhat dangerous if given in plaintext. As such, it returns an object that contains the encrypted version. The -Force option is depreciated and I appreciate you bringing it to my attention, as it was meant to be removed.

You are able to unencrypted your API key if you so desire by running (New-Object System.Management.Automation.PSCredential 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password), which is a PowerShell cmdlet built for managing SecureStrings. It uses reversible encryption tied to your user principle (user account on your specific Windows device).

Please let me know if setting the Base URI to the default works. If not, let's run Get-ITGlueUsers or some other command to test that the module is set up properly before continuing on with the ActiveDirectory script troubleshooting.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/itglue/automation/issues/4#issuecomment-359217846, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AhcWTejGejMcLPpvAfytLXUclN7Q91gFks5tMprNgaJpZM4RRulT.

MartinRiley avatar Jan 21 '18 18:01 MartinRiley

@CalebAlbers when i ran it the first time i did use the default baseurl. (it was the http://api.itglue.com) And it did not work then. I think when i posted this it was with the base default api url.

I later on tried to do it with the company url and kept having the same problem.

I havent run the Get-ITGlueUsers yet. You have any kind of reference of how i can see that i do it in the correct way and get the correct output.

Or is there a way (maybe email) we can have some contact where i can sent some screenies :)

First time working with Powershell Scripts so i might completly forget something or do something totally wrong. I have screenshots of the time i posted this.

Greetings

MartinRiley avatar Jan 23 '18 14:01 MartinRiley

PS C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI> Get-ITGlueUsers

data links meta


{@{id=68079; type=users; attributes=... @{current-page=1; next-page=; prev-p...

PS C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI>

as you can see this is the outcome for the get users command.

MartinRiley avatar Jan 23 '18 14:01 MartinRiley

Getting Global Catalog Servers (Domain Controllers)... DC02,DC01,DC03,DC04 Active Directory flex asset configuration file found! No flexible asset id was found... creating a new flexible asset. Invoke-RestMethod : {"errors":[{"status":422,"title":"Unprocessable Entity","detail":"Request contains invalid trait keys","source":{"pointer":"data/attributes/traits"}}]} At C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI\Resources\FlexibleAssets.ps1:12 char:20

  • $rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $re ...
    
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    
    
    

PS C:\Users\jhill\Downloads\Active Directory> $output.data.attributes.'name-key' forest-name domain-full-name domain-short-name ad-level schema-master domain-naming-master relative-id-rid-master pdc-emulator-master infrastructure-master global-catalog-servers-domain-controllers

api_config-ActiveDirectory.psd1:
#>

key_name_ADForestName = 'forest-name' key_name_DomainName = 'domain-full-name' key_name_DomainShortName = 'domain-short-name' key_name_ADFunctionalLevel = 'ad-level' key_name_SchemaMaster = 'schema-master' key_name_DomainNamingMaster = 'domain-naming-master' key_name_RIDMaster = 'relative-id-master' key_name_PDCEmulator = 'pdc-emulator-master' key_name_InfrastructureMaster = 'infrastructure-master' key_name_GlobalCatalogServers = 'global-catalog-servers-domain-controllers'

Any ideas? I've already completely deleted the Flexible Asset and recreated it to no avail.

jhill777 avatar Mar 02 '18 23:03 jhill777

relative-id-rid-master?

reneehildebrand avatar Mar 02 '18 23:03 reneehildebrand

Wow...I'm embarrassed to admit how long I stared at this. Thank you!!!!!!

jhill777 avatar Mar 03 '18 02:03 jhill777

Is there a limitation on 2016 for the AD level? Invoke-RestMethod : {"errors":[{"source":{"pointer":"/data/attributes/flexible-asset-traits.ad level"},"detail":["can't be blank"],"title":"Unprocessable Entity","status":422}]} At C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI\Resources\FlexibleAssets.ps1:12 char:20

  • ... st_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc eption
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

jhill777 avatar Mar 23 '18 19:03 jhill777

Did something change? Trying to run the active directory integration on a server that has completed successfully in the past. Getting errors now.

Active Directory flex asset configuration file found! Exception calling "Add" with "2" argument(s): "An item with the same key has already been added." At C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI\Resources\Configurations.ps1:90 char:5

  • $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Aut ...
    
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ArgumentException
    
    

Cannot index into a null array. At C:\ITGlue\Active Directory\ActiveDirectory.ps1:175 char:5

  • $api__SchemaMaster_id = (Get-ITGlueConfigurations -filter_organization_id $a ...
    
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

Cannot index into a null array. At C:\ITGlue\Active Directory\ActiveDirectory.ps1:176 char:5

  • $api__DomainNamingMaster_id = (Get-ITGlueConfigurations -filter_organization ...
    
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

Cannot index into a null array. At C:\ITGlue\Active Directory\ActiveDirectory.ps1:177 char:5

  • $api__RIDMaster_id = (Get-ITGlueConfigurations -filter_organization_id $api_ ...
    
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

Cannot index into a null array. At C:\ITGlue\Active Directory\ActiveDirectory.ps1:178 char:5

  • $api__PDCEmulator_id = (Get-ITGlueConfigurations -filter_organization_id $ap ...
    
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

Cannot index into a null array. At C:\ITGlue\Active Directory\ActiveDirectory.ps1:179 char:5

  • $api__InfrastructureMaster_id = (Get-ITGlueConfigurations -filter_organizati ...
    
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

Cannot index into a null array. At C:\ITGlue\Active Directory\ActiveDirectory.ps1:185 char:9

  •     $tmp_global_catalog_ids[$idx] = (Get-ITGlueConfigurations -filter_organi ...
    
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

No flexible asset id was found... creating a new flexible asset. Invoke-RestMethod : {"errors":[{"status":401,"title":"Unauthorized","detail":"Unauthorized resource access","source":{"pointer":"id"}}]} At C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI\Resources\FlexibleAssets.ps1:12 char:20

  • $rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $re ...
    
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
     eption
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    

jhill777 avatar Jul 25 '19 18:07 jhill777

Oddly enough I'm getting the same as the original poster for a new client. Works fine at another client and creates and or updates the existing AD flexible asset. When I try at this client i get `Active Directory flex asset configuration file found! No flexible asset id was found... creating a new flexible asset. New-ITGlueFlexibleAssets : {"errors":[{"status":401,"title":"Unauthorized","detail":"Unauthorized resource access","source":{"pointer":"id"}}]} At C:\jobs\ActiveDirectory.ps1:338 char:41

  •                 $api__output_data = New-ITGlueFlexibleAssets -data $api__bod ...
    
  •                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-ITGlueFlexibleAssets`

get-itglueusers, (get-itglueorganizations).data both return valid data. Same api key is used at each location.

AHelsby avatar Jan 19 '22 19:01 AHelsby