AjeratoMailManager/Ajera-ListProjects.ps1

104 lines
2.8 KiB
PowerShell
Raw Permalink Normal View History

2024-03-08 10:38:23 -07:00
<#
https://help.deltek.com/Product/Ajera/api/projects.html#messages-api-endpoint-post
#>
2024-04-09 16:30:03 -06:00
$MPE_Ajera_URI = "https://ajera.mpe.ca/ajera/AjeraAPI.ashx?ew0KICAiRGF0YWJhc2VOYW1lIjogIkFqZXJhIg0KfQ%3d%3d"
$Headers = @{
'Content-Type' = 'application/json'
Accept = 'application/json'
}
2024-09-03 14:54:45 -06:00
$Project_Out = @()
function Connect-Ajera {
2024-03-08 10:38:23 -07:00
$Session_Body = @{
Method = "CreateAPISession"
Username = "MMIntegration"
2024-04-09 16:30:03 -06:00
Password = "@s0Nny2day"
2024-09-03 14:54:45 -06:00
APIVersion = 1
UseSessionCookie = $false
} | ConvertTo-Json
2024-03-08 10:38:23 -07:00
2024-09-03 14:54:45 -06:00
$Session_token = Invoke-WebRequest -Uri $MPE_Ajera_URI -Method Post -Body $Session_Body -Headers $Headers
return $Session_token
}
function Disconnect-Ajera {
param (
$Token_to_Kill
)
$Session_Body = @{
Method = "EndAPISession"
SessionToken = $Token_to_Kill
} | ConvertTo-Json
2024-09-03 14:54:45 -06:00
$resp = Invoke-WebRequest $MPE_Ajera_URI -Headers $Headers -Body $Session_Body
return $null
}
if (!($APIKey)) {
# get session api key if not already loaded
$Session = Connect-Ajera
2024-04-09 16:30:03 -06:00
$resp = $Session.Content | ConvertFrom-Json
$APIKey = $resp.Content.SessionToken
}
2024-03-08 10:38:23 -07:00
$req_body = @{
2024-04-09 16:30:03 -06:00
Method = 'ListProjects'
SessionToken = $APIKey
2024-03-08 10:38:23 -07:00
MethodArguments = @{
2024-04-09 16:30:03 -06:00
FilterByStatus = @("Active")
2024-03-08 10:38:23 -07:00
}
} | ConvertTo-Json
2024-09-03 14:54:45 -06:00
$resp = Invoke-WebRequest -Uri $MPE_Ajera_URI -Headers $Headers -Body $req_body -Method Post
$projects = ($resp.Content | convertfrom-json).Content.projects
foreach ($project in $projects) {
# Get Client name for each project.
$req_body = @{
Method = 'GetProjects'
SessionToken = $APIKey
MethodArguments = @{
RequestedProjects = @($project.ProjectKey)
}
} | ConvertTo-Json
$resp = Invoke-WebRequest -Uri $MPE_Ajera_URI -Headers $Headers -Body $req_body -Method Post
$project_info = ($resp.Content | ConvertFrom-Json).Content
$Project_SharePoint_FolderName = $project.ID + "-" + $project_info.Projects.InvoiceGroups.Client.Description + '-' + $project.Description
$Project_Out += [PSCustomObject]@{
ProjectNumber = $project.ID
ProjectClient = $project_info.Projects.InvoiceGroups.Client.Description
ProjectName = $project.Description
Project_Ajera_LastUpdate = $project_info.Projects.LastModifiedDate
Project_SharePoint_TimeStamp = $null
Project_SharePoint_FolderName = $Project_SharePoint_FolderName
}
}
## Disconnect from Ajera.
$APIKey = Disconnect-Ajera -Token_to_Kill $APIKey
$Project_Out | out-gridview
# Now, we connect to sharepoint online and add folders
# Set the library URL and subfolder name
$libraryUrl = "https://mpeeng.sharepoint.com/sites/MPEProjectEmails/Shared Documents"
$subfolderName = "New Subfolder"
2024-09-03 14:54:45 -06:00
# Create the subfolder