简体   繁体   English

如何使用 Graph API 和 PowerShell 将 OneNote 笔记本选项卡添加到 Teams 频道?

[英]How to add a OneNote notebook tab to Teams channel using Graph API and PowerShell?

I'm trying to add a tab containing a OneNote notebook into my MS Teams channel using Graph API.我正在尝试使用 Graph API 将包含 OneNote 笔记本的选项卡添加到我的 MS Teams 频道中。 I found this usefull blog post that is explaining how to do this.我发现这篇有用的博客文章解释了如何做到这一点。 Unofortunetely I did not manage to go to the end.不幸的是我没能走到最后。 I'm stuck to the step when he is creating a OneNote in the Teams, whatever that means.当他在 Teams 中创建 OneNote 时,我一直坚持这一步,无论这意味着什么。

Here is a picture of my Microsoft Graph Explorer windows:这是我的 Microsoft Graph Explorer 窗口的图片:

在此处输入图片说明

FYI my Request body section contains the following code :仅供参考,我的请求正文部分包含以下代码:

{
    "displayName": "OneNote"
}

Here is my PowerShell.这是我的 PowerShell。 The variables that are not initialized have actual values (personnal or irrelevant for this post).未初始化的变量具有实际值(个人的或与本文无关的)。 They are properly defined because i'm getting all I want to.它们被正确定义,因为我得到了我想要的一切。 Only the last request invocation is not working.只有最后一次请求调用不起作用。

$graphAPIUrl = "https://graph.microsoft.com/v1.0/"
$teamTitle = "My teams"

# Connecting to AzureAD Services
Connect-AzureAD -Credential $creds

# Connecting to Graph API services
Connect-PnPOnline -ClientId $GraphAppId -ClientSecret $GraphAppSecret -AADDomain $AADDomain

# Getting access token
$token = Get-PnPGraphAccessToken
$headers = @{
    "Authorization"="Bearer " + $token;
    "Content-Type"= "application/json";
    "Content-length" = 200;
}

# Getting current team group ID
$getAllGroupsRequest = "$($graphAPIUrl)groups"
$groups = Invoke-RestMethod -Uri $getAllGroupsRequest -Headers $headers -Method "GET"
$groupId = ($groups.value | Where-Object displayName -eq $teamTitle).id

# Getting site collection ID
$getRootSiteInfoRequest = "$($graphAPIUrl)groups/$($groupId)/sites/root"
$siteCollectionInfos = Invoke-RestMethod -Uri $getRootSiteInfoRequest -Headers $headers -Method "GET"

# Getting site ID
$siteCollectionId = (($siteCollectionInfos.value).id -Split ",")[1]
$siteId = (($siteCollectionInfos.value).id -Split ",")[2]

# Creating the notebook in teams
$createNoteBookRequest = "$($graphAPIUrl)groups/$($groupId)/onenote/notebooks"
$body = @{
    "displayName" = "OneNote"
}
$formatedBody = ConvertTo-Json -InputObject $body
$createdGroup = Invoke-RestMethod -Uri $getRootSiteInfoRequest -Headers $headers -Method "POST" -Body $body

When I launch the snippet above I'm getting the following message:当我启动上面的代码片段时,我收到以下消息:

Invoke-RestMethod : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse

What am I doing wrong ?我究竟做错了什么 ?

Invoke-RestMethod 适用于“GET”操作,但它似乎不适用于 POST 操作,因此尝试将上面发布的最后一行,即带有“body”的 Invoke-WebRequest 转换为

$createdGroup = Invoke-WebRequest -Uri -Headers $headers -ContentType 'application/json' -Method "POST" -Body $body

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Teams Graph API:向团队添加频道失败并显示404 - Microsoft Teams Graph API: Add channel to teams is failing with a 404 如何使用 PowerShell Azure 函数和 Graph API 创建 Microsoft Teams 团队? - How to create a Microsoft Teams team using a PowerShell Azure function and the Graph API? 如何使用Powershell中的OneNote REST API在HTML正文中包含图像数据? - How to include image data in the HTML body using OneNote's REST API from Powershell? 如何通过 PowerShell 或图形 API 在 Micosoft Teams 中设置成员设置“允许成员上传自定义应用程序” - How to set membersetting “allow member to upload custom apps” in Micosoft Teams via PowerShell or Graph API 使用 Graph 在 PowerShell 中创建 Teams 会议 - Creating Teams meetings in PowerShell with Graph 如何通过 Graph API 或 PowerShell 添加 Azure Active Directory 角色? - How to add Azure Active Directory role via Graph API or PowerShell? PowerShell和Onenote - PowerShell and Onenote 如何使用 Powershell 在 OneNote 文件中搜索文本 - How to search text in OneNote file with Powershell 如何通过 PowerShell 设置 Microsoft Teams 通用频道权限 - How do I set Microsoft Teams General Channel Permissions through PowerShell 使用 MS Graph(或 PowerShell)创建 MS Teams 聊天 - Create MS Teams chats with MS Graph (or PowerShell)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM