1+ # !/usr/bin/env pwsh
2+ # Requires -Version 6
3+ # Requires -Modules Microsoft .PowerShell .Utility , Microsoft .PowerShell .Management
4+
5+ using namespace System ;
6+ using namespace System.IO ;
7+
8+
9+ [CmdletBinding (
10+ SupportsPaging = $false ,
11+ RemotingCapability = ' None' ,
12+ SupportsTransactions = $false ,
13+ SupportsShouldProcess = $false ,
14+ HelpUri = ' https://support.sowder.io'
15+ )]
16+ [OutputType ([FileInfo []])]
17+ param (
18+ [Parameter (Mandatory = $true , HelpMessage = ' ConnectWise Manage API version' )]
19+ [string ] $ConnectWiseManageAPIVersion ,
20+
21+ [Parameter (Mandatory = $false , HelpMessage = ' Output directory' )]
22+ [string ] $OutputPath = ' api' ,
23+
24+ [Parameter (Mandatory = $false , HelpMessage = ' Optional flag to also fetch other ConnectWise product Open API specs' )]
25+ [switch ] $IncludeOtherProductSpecs
26+ );
27+
28+ Set-StrictMode - Version ' Latest' ;
29+
30+ Import-Module ' Microsoft.PowerShell.Utility' ;
31+ Import-Module ' Microsoft.PowerShell.Management' ;
32+
33+
34+ if (! (Test-Path - Path $OutputPath )) {
35+ New-Item - Path $OutputPath - ItemType ' Directory' - Force | Out-Null ;
36+ }
37+ [string ] $tmpPath = [Path ]::GetTempPath();
38+ [string ] $tmpFolder = [Path ]::GetFileNameWithoutExtension([Path ]::GetRandomFileName());
39+ [DirectoryInfo ] $workingDirectory = New-Item - Path $tmpPath - Name $tmpFolder - ItemType ' Directory' ;
40+
41+ @ (' Service' , ' Company' , ' Expense' , ' Finance' , ' Marketing' , ' Procurement' , ' Project' , ' Sales' , ' Schedule' , ' System' , ' Time' ) | ForEach-Object {
42+ $params = @ {
43+ Method = ' GET'
44+ Uri = " https://api-na.myconnectwise.net/$ ( $ConnectWiseManageAPIVersion ) /services/ApiTools/ApiDocumentation/json/$ ( $_ ) .json"
45+ OutFile = " $ ( $workingDirectory.FullName ) /$ ( $_.ToLower ()) .json"
46+ };
47+ Invoke-RestMethod @params ;
48+ }
49+ Get-ChildItem - Path $workingDirectory.FullName - File | Get-Content - Raw | & npx json -- deep- merge >> " $ ( $OutputPath ) /manage.json" ;
50+ Remove-Item - Path $workingDirectory - Recurse - Force | Out-Null ;
51+ if ($IncludeOtherProductSpecs.IsPresent ) {
52+ # ConnectWise Automate
53+ Invoke-RestMethod - Method ' GET' - Uri ' https://marketplace.connectwise.com/docs/openapi/json/Automate.txt' - OutFile " $ ( $OutputPath ) /automate.json" ;
54+
55+ # ConnectWise Control
56+ Invoke-RestMethod - Method ' GET' - Uri ' https://marketplace.connectwise.com/docs/openapi/json/Control.txt' - OutFile " $ ( $OutputPath ) /control.json" ;
57+
58+ # ConnectWise Sell
59+ Invoke-RestMethod - Method ' GET' - Uri ' https://marketplace.connectwise.com/docs/openapi/json/Sell.txt' - OutFile " $ ( $OutputPath ) /sell.json"
60+ }
61+ Get-ChildItem - Path $OutputPath - File;
0 commit comments