close, but not getting session token properly.

This commit is contained in:
Erik Eckert 2024-04-09 10:26:55 -06:00
parent b6af450fa7
commit 8d4ee36c44

View File

@ -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 = @{ $req_body = @{
Method = 'ListProjects' Method = 'GetProjects'
SessionToken = '' SessionToken = $APIKey
MethodArguments = @{ MethodArguments = @{
FilterByStatus = '["Active", "Hold"]' 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"
} }
} } | ConvertTo-Json
$resp = Invoke-WebRequest -Uri $API_URI -Headers $Headers -Body $req_body -Method Post -SkipCertificateCheck