Forum Discussion
Adrian Tupper
Jun 05, 2023Copper Contributor
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 ?
- As clearly stated in the documentation, application permissions are not supported for this operation: https://learn.microsoft.com/en-us/graph/api/channel-provisionemail?view=graph-rest-1.0&tabs=http
Use delegate permissions, and make sure the user you're running under has enough permissions (being a member of the Team is usually enough).- Adrian TupperCopper ContributorHello,
Exactly! that's why I'm using User Context instead... The problem is that I'm not a member of all the teams, I need to generate the mail for...
Do I need to add the account to all the teams before generating the email ?
Regards,
Adrian- Afaik that's the only way.