KelvinTegelaar / AutotaskAPI

Autotask 2020.2 REST API PowerShell wrapper
https://cyberdrain.com
MIT License
67 stars 25 forks source link

Enhance New-AutotaskAPIResource #24

Closed robgilbreath closed 4 years ago

robgilbreath commented 4 years ago

These changes came from my modifications allowing me to use the module to upload ticket attachments. There are three sets of related changes in this PR:

  1. New-AutotaskBody currently pulls from the $Script:PatchParameter for its picklist. However, some entities do not have patch methods, only post methods. To address this I
    • Modifed New-ResourceDynamicParameter so that it can iterate over multiple methods and provide a picklist of entities with either a post or a patch method
    • Modifed Add-AutotaskBaseURI so it creates an additional PostPatchParameter variable with all entities with either a post or a patch method
    • Modifed New-AutotaskBody so it uses that PostPatchParameter for its picklist and also checks post and patch queries for a url
  2. Some entities do not have UDFs, and when using New-AutotaskBody on these the function fails when it gets a 404. To address this I
    • Added try/catch around UDF query so that 404 responses do not cause the function to error out (non 404 errors do terminate)
  3. New-AutotaskAPIResource does not handle child entities. To address this I
    • Added optional parameter ParentId. If a child resource is specified but no parent id is provided, function breaks with informative note.

One note - In order to support child resources, the changes I made to New-AutotaskAPIResource could probably be applied identically to Set-AutotaskAPIResource. However, I don't currently have a use case (or time) to test. In addition, I know you are probably working on child resource enhancements that might conflict with what I did in New-AutotaskAPIResource. If there are conflicts or if this PR feels too targeted, I'm open to making adjustments.

KelvinTegelaar commented 4 years ago

Changes don't seem to conflict anywhere with planned changes, Looks good. Will be published in next release.

Thanks @robgilbreath. Great contributions. <3