diff --git a/Ajera-ListProjects.ps1 b/Ajera-ListProjects.ps1 index 7334209..1b2edd3 100644 --- a/Ajera-ListProjects.ps1 +++ b/Ajera-ListProjects.ps1 @@ -3,25 +3,60 @@ https://help.deltek.com/Product/Ajera/api/projects.html#messages-api-endpoint-po #> +$MPE_Ajera_URI = "https://192.168.2.19/ajera/AjeraAPI.ashx" +$Headers = @{ + 'Content-Type' = 'application/json' + Accept = 'application/json' +} +function Connect-Ajera { + + $Session_Body = @{ + Method = "CreateAPISession" + Username = "MMIntegration" + Password = "DeluxeMXD74!" + APIVersion = 2 + UseSessionCookie = $false + } | ConvertTo-Json -$MPE_Ajera_URI = "https://ajera.mpe.ca/ajera/AjeraAPI.ashx" -$MPE_Ajera_API_Token = + + $session_token_URI = $MPE_Ajera_URI + '?' + $MPE_Ajera_API_Token + $Session_token = Invoke-WebRequest -Uri $session_token_URI -Method Post -Body $Session_Body -Headers $Headers -SkipCertificateCheck + + return $Session_token +} + +function Disconnect-Ajera { + param ( + $Token_to_Kill + ) + $Session_Body = @{ + Method = "EndAPISession" + SessionToken = $Token_to_Kill + } | ConvertTo-Json + + + Invoke-WebRequest $MPE_Ajera_URI -Headers $Headers -Body $Session_Body -SkipCertificateCheck +} + + +if (!($APIKey)) { + # get session api key if not already loaded + $Session = Connect-Ajera + $APIKey = ($Session.Content | ConvertFrom-Json).UsageKey +} + +$API_URI = $MPE_Ajera_URI + '?' + $APIKey $req_body = @{ - Method = 'ListProjects' - SessionToken = '' + Method = 'GetProjects' + SessionToken = $APIKey MethodArguments = @{ - FilterByStatus = '["Active", "Hold"]' - FilterByCompany = '[1]' - FilterByNameLike = "Description" - FilterByDescriptionLike = "Project Description" - FilterByDescriptionEquals = "Project Description" - FilterByIDLike = "03-M4" - FilterByProjectType = '[1, null]' - FilterBySyncToCRM = '[true]' - FilterByEarliestModifiedDate = "2015-03-11" - FilterByLatestModifiedDate = "2015-03-11" + FilterByStatus = '["Active", "Hold"]' } -} \ No newline at end of file +} | ConvertTo-Json + + +$resp = Invoke-WebRequest -Uri $API_URI -Headers $Headers -Body $req_body -Method Post -SkipCertificateCheck +