Public/New-GhostMember.ps1
|
function New-GhostMember { <# .SYNOPSIS Creates a member on the Ghost site. .DESCRIPTION Creates a free member and returns it. Only the email address is required. Ghost refuses an address that a member already has. A new member is subscribed to the newsletters that new members get by default. Name the newsletters yourself with -Newsletters, or pass -Subscribed $false for a member that gets no newsletter. A label that does not exist yet is created. A paid subscription cannot be given with this function: a member gets one by paying. .EXAMPLE New-GhostMember -Email 'jamie@example.com' Creates a free member with only an email address. .EXAMPLE New-GhostMember -Email 'jamie@example.com' -Name 'Jamie Larson' -Labels 'VIP', 'Imported' -Note 'From the fair.' Creates a member with a name, two labels and a note that only the staff of the site sees. .EXAMPLE New-GhostMember -Email 'jamie@example.com' -Subscribed $false Creates a member that is not subscribed to any newsletter. .EXAMPLE New-GhostMember -Email 'jamie@example.com' -CustomField @{ company = 'Ghost' } -WhatIf Shows that a member would be created with a value for the custom field with the key company. .LINK https://docs.ghost.org/admin-api/members/creating-a-member #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Ghost.Member')] param( # Email address of the member. [Parameter(Mandatory, Position = 0)] [ValidateNotNullOrEmpty()] [string] $Email, # Name of the member. [string] $Name, # Note about the member, for the staff of the site only. 2000 characters at most. [string] $Note, # Names of the labels of the member. A label that does not exist yet is created. [string[]] $Labels, # Ids of the newsletters the member is subscribed to. An empty list subscribes to none. [AllowEmptyCollection()] [string[]] $Newsletters, # $false creates a member that gets no newsletter, $true one that gets the default newsletters. [bool] $Subscribed, # Values for the custom fields of members: the key of a field and its value, such as # @{ company = 'Ghost' }. Ghost refuses a key that is not a custom field of the site. [System.Collections.IDictionary] $CustomField ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { $parameters = ConvertTo-GhostMemberParameter -Parameters $PSBoundParameters $uri = New-URIString -Endpoint $resources.URI $body = New-BodyString -BodyKeys $resources.Body -Parameters $parameters -Wrapper $resources.Result if ($PSCmdlet.ShouldProcess($Email, $resources.Description)) { $result = Submit-Request -Uri $uri -Method $resources.Method -Body $body -Success $resources.Success $result = Test-ReturnFormat -Result $result -Location $resources.Result Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName } } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |