Forum Discussion

Adrian Tupper's avatar
Adrian Tupper
Copper Contributor
Jun 05, 2023

Generate Channel email address with GraphApi

Hello,

 

I'm trying to generate Channel's email through GraphApi.

It works well when I'm a member of the Teams but when I try to generate one with a Team/Channel, I'm not member of, I receive a weird error "Bad Request"

I've tried through "Application Context" and "Delegate Context" but still not working.  (New-MgTeamChannelEmail can't be use in Application Context though)

 

 

$CLientID="whatever"
$TenantID="whatever2"


$myAccessToken = Get-MsalToken -ClientId $clientID -TenantId $tenantID -Scopes 'https://graph.microsoft.com/.default' -RedirectUri 'https://login.microsoftonline.com/common/oauth2/nativeclient'
# $myAccessToken = Get-MsalToken -ClientId $clientID -TenantId $tenantID -ClientSecret $clientSecret -Scopes 'https://graph.microsoft.com/.default' -RedirectUri 'https://login.microsoftonline.com/common/oauth2/nativeclient'
$token = $myAccessToken.AccessToken
Connect-MgGraph -AccessToken $token

# Set the baseurl to MS Graph-API (BETA API)
$baseUrl = 'https://graph.microsoft.com/1.0'
         
# Pack the token into a header for future API calls
$header = @{
          'Authorization' = "Bearer $($Token)"
}
 
$TeamId="WhateverNumber"
$ChannelId="WhateverNumber"


# write-host $userPurpose.value
$generatedemail = New-MgTeamChannelEmail -TeamId $TeamId  -ChannelId $ChannelId 

 

 

Any ideas ?