Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for User Identity endpoints. #11

Merged
merged 1 commit into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PwshZendesk.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
'Get-TicketFollower', 'Get-ZendeskTicketFollower'
'Get-TicketRelated', 'Get-ZendeskTicketRelated'
'Get-User', 'Get-ZendeskUser'
'Get-UserIdentity', 'Get-ZendeskUserIdentity'
'Get-UserRelated', 'Get-ZendeskUserRelated'
'Hide-Comment', 'Hide-ZendeskComment'
'Import-Ticket', 'Import-ZendeskTicket'
Expand All @@ -111,6 +112,7 @@
'New-GroupMembership', 'New-ZendeskGroupMembership'
'New-OrganizationMembership', 'New-ZendeskOrganizationMembership'
'New-Ticket', 'New-ZendeskTicket'
'New-UserIdentity', 'New-UserIdentity'
'Remove-Attachment', 'Remove-ZendeskAttachment'
'Remove-Group', 'Remove-ZendeskGroup'
'Remove-GroupMembership', 'Remove-ZendeskGroupMembership'
Expand All @@ -119,13 +121,17 @@
'Remove-Tag', 'Remove-ZendeskTag'
'Remove-Ticket', 'Remove-ZendeskTicket'
'Remove-User', 'Remove-ZendeskUser'
'Remove-UserIdentity', 'Remove-ZendeskUserIdentity'
'Restore-DeletedTicket', 'Restore-ZendeskDeletedTicket'
'Restore-SuspendedTicket', 'Restore-ZendeskSuspendedTicket'
'Search-', 'Search-Zendesk'
'Send-UserIdentityVerification', 'Send-UserIdentityVerification'
'Set-GroupMembershipAsDefault', 'Set-ZendeskGroupMembershipAsDefault'
'Set-OrganizationMembershipAsDefault', 'Set-ZendeskOrganizationMembershipAsDefault'
'Set-Tag', 'Set-ZendeskTag'
'Set-User', 'Set-ZendeskUser'
'Set-UserIdentityAsPrimary', 'Set-ZendeskUserIdentityAsPrimary'
'Set-UserIdentityAsVerified', 'Set-ZendeskUserIdentityAsVerified'
'Test-Connection', 'Test-ZendeskConnection'
'Update-Group', 'Update-ZendeskGroup'
'Update-Ticket', 'Update-ZendeskTicket'
Expand Down
54 changes: 54 additions & 0 deletions functions/Get-UserIdentity.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

function Get-UserIdentity {
<#
.SYNOPSIS
Returns user identities for a given user id.
.DESCRIPTION
Returns all user identities for a given user id or shows the identity with the given id.
.EXAMPLE
PS C:\> Get-UserIdentity -UserId `427427011998`

Gets all User Identities for the User with Id `427427011998`
.EXAMPLE
PS C:\> Get-UserIdentity -UserId `427427011998` -Id `211258542687`

Gets the User Identity `211258542687` for the User with Id `427427011998`
.EXAMPLE
PS C:\> Get-UserIdentity -UserId `427427011998` -Context $context

Gets all User Identities for the User with Id `427427011998` providing the optional Zendesk Context `$context`
#>
[OutputType([PSCustomObject])]
[CMDletBinding()]
Param (
# Unique Id of the user identity to retrieve
[Parameter(Mandatory = $false)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$Id,

# Unique Id of the user to retrieve identities for
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

if ($PSBoundParameters.ContainsKey('Id')) {
$path = "/api/v2/users/$UserId/identities/$Id.json"
$key = 'identity'
} else {
$path = "/api/v2/users/$UserId/identities.json"
$key = 'identities'
}

$result = Invoke-Method -Context $Context -Path $path -Verbose:$VerbosePreference
$result | Select-Object -Expand $key

}
2 changes: 2 additions & 0 deletions functions/Invoke-Method.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ function Invoke-Method {
$params.Body = $Body
}
$params.ContentType = $ContentType

$params.Body | Out-String | Write-Debug
}

$uri = $Context.BaseUrl + $Path
Expand Down
99 changes: 99 additions & 0 deletions functions/New-UserIdentity.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

function New-UserIdentity {
<#
.SYNOPSIS
Adds a new identity to a user's profile.
.DESCRIPTION
Adds a new identity to a user's profile.
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'email' -Value '[email protected]'

Adds the email address `[email protected]` to the user `427427011998`
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'twitter' -Value 'username'

Adds the twitter account `username` to the user `427427011998`
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'facebook' -Value '855769377321'

Adds the facebook account `855769377321` to the user `427427011998`
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'google' -Value '[email protected]'

Adds the google account `[email protected]` to the user `427427011998`
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'phone_number' -Value '+1 555-123-4567'

Adds the phone_number `+1 555-123-4567` to the user `427427011998`
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'agent_fowarding' -Value '+1 555-123-4567'

Adds the agent_fowarding number `+1 555-123-4567` to the user `427427011998`
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'email' -Value '[email protected]' -Verified

Adds the email address `[email protected]` to the user `427427011998` and marks it as verified
.EXAMPLE
PS C:\> New-UserIdentity -UserId '427427011998 -Type 'email' -Value '[email protected]' -Primary

Adds the email address `[email protected]` to the user `427427011998` as their primary identity
.EXAMPLE
PS C:\> New-UserIdentity -Context $context -UserId '427427011998 -Type 'email' -Value '[email protected]'

Adds the email address `[email protected]` to the user `427427011998` using a Zendesk Context returned from `Get-ZendeskConnection`
#>
[OutputType([PSCustomObject])]
[CMDletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High', DefaultParameterSetName = 'Default')]
Param (
# The id of the user
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# The Type of the Identity.
[Parameter(Mandatory = $true)]
[ValidateSet('email', 'twitter', 'facebook', 'google', 'phone_number', 'agent_fowarding', 'sdk')]
[String]
$Type,

# The identifier for this identity, such as an email address
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Value,

# If the identity has been verified
[Parameter(Mandatory = $true, ParameterSetName = 'Verified')]
[Switch]
$Verified,

# If the identity is the primary identity.
[Parameter(Mandatory = $false, ParameterSetName = 'Verified')]
[Switch]
$Primary,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/users/$UserId/identities.json"
$body = @{
identity = @{
user_id = $UserId
type = $Type
value = $Value
verified = [Boolean]$Verified
primary = [Boolean]$Primary
}
}

if ($PSCmdlet.ShouldProcess($Value, 'Add User Identity')) {
$result = Invoke-Method -Context $Context -Method 'Post' -Path $path -Body $body -Verbose:$VerbosePreference
$result
}

}
46 changes: 46 additions & 0 deletions functions/Remove-UserIdentity.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

function Remove-UserIdentity {
<#
.SYNOPSIS
Delete the specified User Identity
.DESCRIPTION
Delete the specified User Identity
.EXAMPLE
PS C:\> Remove-UserIdentity -UserId `427427011998` -Id `211258542687`

Deletes the User Identity `211258542687` for the User with Id `427427011998`
.EXAMPLE
PS C:\> Remove-UserIdentity -Context $context -UserId `427427011998` -Id `211258542687`

Deletes the User Identity `211258542687` for the User with Id `427427011998` specifying the optional Context
#>
[OutputType([PSCustomObject])]
[CMDletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
Param (
# Unique Id of the user identity to delete
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$Id,

# Unique Id of the user whose identity is to be deleted
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/users/$UserId/identities/$Id.json"

if ($PSCmdlet.ShouldProcess($Id, 'Delete User Identity')) {
$result = Invoke-Method -Context $Context -Method 'Delete' -Path $path -Verbose:$VerbosePreference
$result
}

}
42 changes: 42 additions & 0 deletions functions/Send-UserIdentityVerification.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

function Send-UserIdentityVerification {
<#
.SYNOPSIS
Sends the user a verification email with a link to verify ownership of the email address.
.DESCRIPTION
Sends the user a verification email with a link to verify ownership of the email address.
.EXAMPLE
PS C:\> Send-UserIdentityVerification -UserId `427427011998` -Id `211258542687`

Triggers a Zendesk Identity Verification Email for User Identity `211258542687`
#>
[OutputType([PSCustomObject])]
[CMDletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
Param (
# Unique Id of the user identity to verify
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$Id,

# Unique Id of the user whose identity to verify
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/users/$UserId/identities/$Id/request_verification.json"

if ($PSCmdlet.ShouldProcess('Send a User Identity Verification', $Id)) {
$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Verbose:$VerbosePreference
$result
}

}
41 changes: 41 additions & 0 deletions functions/Set-UserIdentityAsPrimary.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

function Set-UserIdentityAsPrimary {
<#
.SYNOPSIS
Sets the specified identity as primary.
.DESCRIPTION
Sets the specified identity as primary.
.EXAMPLE
PS C:\> Set-UserIdentityAsPrimary -UserId `427427011998` -Id `211258542687`

Sets the User Identity `211258542687` for the User with Id `427427011998` as their primary Identity
#>
[OutputType([PSCustomObject])]
[CMDletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
Param (
# Unique Id of the user identity to make primary
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$Id,

# Unique Id of the user
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/users/$UserId/identities/$Id/make_primary"

if ($PSCmdlet.ShouldProcess('Set User Identity as Primary', $Id)) {
$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Verbose:$VerbosePreference
$result
}
}
42 changes: 42 additions & 0 deletions functions/Set-UserIdentityAsVerified.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

function Set-UserIdentityAsVerified {
<#
.SYNOPSIS
Sets the specified identity as verified.
.DESCRIPTION
Sets the specified identity as verified.
.EXAMPLE
PS C:\> Set-UserIdentityAsVerified -UserId `427427011998` -Id `211258542687`

Sets the User Identity `211258542687` for the User with Id `427427011998` as verified
#>
[OutputType([PSCustomObject])]
[CMDletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
Param (
# Unique Id of the user identity to mark as verified
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$Id,

# Unique Id of the user
[Parameter(Mandatory = $true)]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/users/$UserId/identities/$Id/verify"

if ($PSCmdlet.ShouldProcess('Set User Identity as Verified', $Id)) {
$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Verbose:$VerbosePreference
$result
}

}
Loading