调用SharePoint REST API注册Container Type时遇apiNotFound错误
我正在尝试调用SharePoint REST API注册新的SharePoint Embedded容器类型,流程参考微软官方教程。没有使用Postman,而是用C#实现自动化注册逻辑。
最初尝试把教程里的前置JavaScript逻辑转成C#,后来改用MSAL获取访问令牌,目前认证环节没有报错,获取令牌的代码如下:
X509Certificate2 appCertificate = GetAppCertificate(); IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create( this.Configuration.ClientAppId ) .WithTenantId( this.Configuration.ConsumingTenantId ) .WithCertificate( appCertificate ) .Build(); AuthenticationResult authenticationResult = await app.AcquireTokenForClient( new List<string> { this.Configuration.RootSiteUrl + "/.default" } ) .ExecuteAsync(); return authenticationResult.AccessToken;
但调用容器类型注册接口时,收到apiNotFound错误,相关代码如下:
string payload = $$""" { "value": [ { "appId": "{{this.Configuration.ClientAppId}}", "delegated": ["full"], "appOnly": ["full"] } ] } """; httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Bearer", token ); string url = $"{this.Configuration.RootSiteUrl}/_api/v2.1/storageContainerTypes/{this.Configuration.ContainerTypeId}/applicationPermissions"; var response = await httpClient.PostAsync( url, new StringContent( payload, Encoding.UTF8, "application/json" ) );
一开始怀疑是没有启用SharePoint Embedded功能,但找不到对应的设置项,而且相关视频说明该设置仅预览版需要,推测现在已经默认启用。找到的唯一相关参考是关于GraphAPI的输入错误问题,但我调用的是原生SharePoint REST API,和该情况不符。
内容的提问来源于stack exchange,提问作者Mitten.O
相关产品推荐
相关产品推荐

