1+ <#
2+ . SYNOPSIS
3+ Creates a new project in a specified workspace in Toggl.
4+
5+ . DESCRIPTION
6+ This cmdlet creates a new project in a specified workspace in Toggl. It sends a POST request to the Toggl API.
7+
8+ . PARAMETER ApiToken
9+ The API token for authentication. (Mandatory)
10+
11+ . PARAMETER WorkspaceId
12+ Numeric ID of the workspace. (Mandatory)
13+
14+ . PARAMETER Name
15+ Project name. (Mandatory)
16+
17+ . PARAMETER Active
18+ Whether the project is active or archived. (Optional)
19+
20+ . PARAMETER AutoEstimates
21+ Whether estimates are based on task hours, optional, premium feature. (Optional)
22+
23+ . PARAMETER Billable
24+ Whether the project is set as billable, optional, premium feature. (Optional)
25+
26+ . PARAMETER ClientId
27+ Client ID, optional. (Optional)
28+
29+ . PARAMETER ClientName
30+ Client name, optional. (Optional)
31+
32+ . PARAMETER Color
33+ Project color. (Optional)
34+
35+ . PARAMETER Currency
36+ Project currency, optional, premium feature. (Optional)
37+
38+ . PARAMETER EndDate
39+ End date of a project timeframe. (Optional)
40+
41+ . PARAMETER EstimatedHours
42+ Estimated hours, optional, premium feature. (Optional)
43+
44+ . PARAMETER ExternalReference
45+ External reference. (Optional)
46+
47+ . PARAMETER FixedFee
48+ Project fixed fee, optional, premium feature. (Optional)
49+
50+ . PARAMETER IsPrivate
51+ Whether the project is private or not. (Optional)
52+
53+ . PARAMETER IsShared
54+ Whether the project is shared. (Optional)
55+
56+ . PARAMETER Rate
57+ Hourly rate, optional, premium feature. (Optional)
58+
59+ . PARAMETER RateChangeMode
60+ Rate change mode, optional, premium feature. Can be "start-today", "override-current", "override-all". (Optional)
61+
62+ . PARAMETER Recurring
63+ Whether the project is recurring, optional, premium feature. (Optional)
64+
65+ . PARAMETER RecurringParameters
66+ Project recurring parameters, optional, premium feature. (Optional)
67+
68+ . PARAMETER StartDate
69+ Start date of a project timeframe. (Optional)
70+
71+ . PARAMETER Template
72+ Whether the project is a template, optional, premium feature. (Optional)
73+
74+ . PARAMETER TemplateId
75+ Template ID, optional. (Optional)
76+
77+ . EXAMPLE
78+ New-TogglProject -ApiToken "your_api_token" -WorkspaceId 123456 -Name "New Project"
79+ #>
80+ function New-TogglProject {
81+ [CmdletBinding ()]
82+ param (
83+ [Parameter (Mandatory = $true )]
84+ [string ]$ApiToken ,
85+
86+ [Parameter (Mandatory = $true )]
87+ [int ]$WorkspaceId ,
88+
89+ [Parameter (Mandatory = $true )]
90+ [string ]$Name ,
91+
92+ [bool ]$Active ,
93+
94+ [bool ]$AutoEstimates ,
95+
96+ [bool ]$Billable ,
97+
98+ [int ]$ClientId ,
99+
100+ [string ]$ClientName ,
101+
102+ [string ]$Color ,
103+
104+ [string ]$Currency ,
105+
106+ [string ]$EndDate ,
107+
108+ [int ]$EstimatedHours ,
109+
110+ [string ]$ExternalReference ,
111+
112+ [decimal ]$FixedFee ,
113+
114+ [bool ]$IsPrivate ,
115+
116+ [bool ]$IsShared ,
117+
118+ [decimal ]$Rate ,
119+
120+ [string ]$RateChangeMode ,
121+
122+ [bool ]$Recurring ,
123+
124+ [psobject ]$RecurringParameters ,
125+
126+ [string ]$StartDate ,
127+
128+ [bool ]$Template ,
129+
130+ [int ]$TemplateId
131+ )
132+
133+ $url = " $Global :TogglBaseUrl /workspaces/$WorkspaceId /projects"
134+
135+ $body = @ {
136+ name = $Name
137+ }
138+
139+ if ($PSBoundParameters.ContainsKey (' Active' )) { $body.active = $Active }
140+ if ($PSBoundParameters.ContainsKey (' AutoEstimates' )) { $body.auto_estimates = $AutoEstimates }
141+ if ($PSBoundParameters.ContainsKey (' Billable' )) { $body.billable = $Billable }
142+ if ($PSBoundParameters.ContainsKey (' ClientId' )) { $body.client_id = $ClientId }
143+ if ($PSBoundParameters.ContainsKey (' ClientName' )) { $body.client_name = $ClientName }
144+ if ($PSBoundParameters.ContainsKey (' Color' )) { $body.color = $Color }
145+ if ($PSBoundParameters.ContainsKey (' Currency' )) { $body.currency = $Currency }
146+ if ($PSBoundParameters.ContainsKey (' EndDate' )) { $body.end_date = $EndDate }
147+ if ($PSBoundParameters.ContainsKey (' EstimatedHours' )) { $body.estimated_hours = $EstimatedHours }
148+ if ($PSBoundParameters.ContainsKey (' ExternalReference' )) { $body.external_reference = $ExternalReference }
149+ if ($PSBoundParameters.ContainsKey (' FixedFee' )) { $body.fixed_fee = $FixedFee }
150+ if ($PSBoundParameters.ContainsKey (' IsPrivate' )) { $body.is_private = $IsPrivate }
151+ if ($PSBoundParameters.ContainsKey (' IsShared' )) { $body.is_shared = $IsShared }
152+ if ($PSBoundParameters.ContainsKey (' Rate' )) { $body.rate = $Rate }
153+ if ($PSBoundParameters.ContainsKey (' RateChangeMode' )) { $body.rate_change_mode = $RateChangeMode }
154+ if ($PSBoundParameters.ContainsKey (' Recurring' )) { $body.recurring = $Recurring }
155+ if ($PSBoundParameters.ContainsKey (' RecurringParameters' )) { $body.recurring_parameters = $RecurringParameters }
156+ if ($PSBoundParameters.ContainsKey (' StartDate' )) { $body.start_date = $StartDate }
157+ if ($PSBoundParameters.ContainsKey (' Template' )) { $body.template = $Template }
158+ if ($PSBoundParameters.ContainsKey (' TemplateId' )) { $body.template_id = $TemplateId }
159+
160+ $jsonBody = $body | ConvertTo-Json - Compress - Depth 10
161+
162+ $headers = Get-TogglAuthHeader - ApiToken $ApiToken
163+ $headers.Add (" Content-Type" , " application/json" )
164+
165+ try {
166+ $response = Invoke-RestMethod - Uri $url - Method Post - Headers $headers - Body $jsonBody
167+ return $response
168+ }
169+ catch {
170+ Write-Error " Failed to create project: $_ "
171+ }
172+ }
173+
174+ Export-ModuleMember - Function New-TogglProject
0 commit comments