英文:
msgraph-sdk-go can't create more than two extensions on a user
问题
当我尝试在用户上创建模式扩展时,如下所示:
schemaExtension := graphmodels.NewSchemaExtension()
additionalData := map[string]interface{}{
"extensionName": "dean.ext.test.1",
"theme": "dark",
"color": "purple",
"lang": "English",
}
schemaExtension.SetAdditionalData(additionalData)
if result, err := client.UsersById(userId).Extensions().Post(context.Background(), schemaExtension, nil); err != nil {
我收到以下错误:
Error: error status code received from the API
code: BadRequest
msg: Maximum number of extensions values supported per application is 2.
但是我没有在该用户上创建任何模式扩展。我创建了两个开放扩展,但我应该能够创建其他模式扩展。
为什么错误消息说扩展是每个应用程序的?上面的代码试图在特定用户上创建扩展,而不是应用程序。
我想要删除此用户上的扩展,但是我在门户中找不到显示用户扩展的任何内容。在门户中,我可以在哪里找到用户的扩展?
门户确实显示适用于所有用户的用户属性。用户属性与扩展有关吗?如何使用msgraph-sdk-go访问这些用户属性?
英文:
When I try to create an schema extension on a user like this
schemaExtension := graphmodels.NewSchemaExtension()
additionalData := map[string]interface{}{
"extensionName": "dean.ext.test.1",
"theme": "dark",
"color": "purple",
"lang": "English",
}
schemaExtension.SetAdditionalData(additionalData)
if result, err := client.UsersById(userId).Extensions().Post(context.Background(), schemaExtension, nil); err != nil {
I get this error:
Error: error status code received from the API
code: BadRequest
msg: Maximum number of extensions values supported per application is 2.
But I have not created any schema extensions on this user. I created two open extensions, but I should be able to create additional schema extensions.
Why does the error message say that extensions are per application? The code above is trying to create an extension on a particular user, not an application.
I want to remove the extensions on this user, but there is nothing I can find in the portal that shows extensions for a user. Where can I find the extensions on a user in the portal?
The portal does show user attributes which seem to apply to all users. Are user attributes related to extensions? How can I access these user attributes using the msgraph-sdk-go?
答案1
得分: 1
msgraph-sdk-go目前版本为0.55,仅为非生产预览版。
在与一些同事讨论后,我们决定放弃MS Graph SDK,直接使用v1.0 Graph REST端点。他们在这种方法上取得了成功,并发现SDK并没有提供太多帮助。
英文:
The msgraph-sdk-go is currently at v 0.55 and is a non-production preview.
After discussing this with some colleagues we've decided to drop the MS Graph SDK and use the v 1.0 Graph REST endpoints directly. They've had success with that approach and have found that the SDK doesn't help very much.
答案2
得分: 0
我尝试在我的环境中复现了相同的情况,并得到了以下结果:
当我在Graph Explorer中运行以下请求来创建扩展时,我得到了与你相同的错误,如下所示:
POST https://graph.microsoft.com/v1.0/users/<userID>/extensions
{
"extensionName": "dean.ext.test.1",
"theme": "dark",
"color": "purple",
"lang": "English"
}
响应:
请注意,你只能为任何目录资源(如用户、组、设备等)创建2个开放扩展。要确认这一点,你可以查看此MS文档中的限制。
如果你的目录中已经存在2个开放扩展,通常会出现此错误。你可以使用以下MS Graph查询列出用户的开放扩展。
GET https://graph.microsoft.com/v1.0/users/<userID>/extensions
响应:
你可以使用以下代码使用msgraph-sdk-go
获取相同的结果:
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.UsersById("user-id").Extensions().Get(context.Background(), nil)
要从用户中删除扩展,你可以使用以下查询,其中包括扩展名称:
DELETE https://graph.microsoft.com/v1.0/users/<userID>/extensions/<extension_name>
响应:
你可以使用以下代码使用msgraph-sdk-go
从用户中删除开放扩展:
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
graphClient.UsersById("user-id").ExtensionsById("extension-id").Delete(context.Background(), nil)
当我现在运行查询以列出开放扩展时,我只得到1个扩展作为响应,因为另一个已成功删除,如下所示:
GET https://graph.microsoft.com/v1.0/users/<userID>/extensions
响应:
你目前使用的代码用于创建模式扩展,而不是创建开放扩展
。
要使用msgraph-sdk-go
创建模式扩展,请与以下示例代码进行交叉检查:
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := graphmodels.NewSchemaExtension()
id := "domainName_schemaName"
requestBody.SetId(&id)
description := "My schema extension"
requestBody.SetDescription(&description)
targetTypes := []string {
"User",
}
requestBody.SetTargetTypes(targetTypes)
extensionSchemaProperty := graphmodels.NewExtensionSchemaProperty()
name := "theme"
extensionSchemaProperty.SetName(&name)
type := "String"
extensionSchemaProperty.SetType(&type)
extensionSchemaProperty1 := graphmodels.NewExtensionSchemaProperty()
name := "color"
extensionSchemaProperty1.SetName(&name)
type := "String"
extensionSchemaProperty1.SetType(&type)
extensionSchemaProperty2 := graphmodels.NewExtensionSchemaProperty()
name := "lang"
extensionSchemaProperty2.SetName(&name)
type := "String"
extensionSchemaProperty2.SetType(&type)
properties := []graphmodels.ExtensionSchemaPropertyable {
extensionSchemaProperty,
extensionSchemaProperty1,
extensionSchemaProperty2,
}
requestBody.SetProperties(properties)
result, err := graphClient.SchemaExtensions().Post(context.Background(), requestBody, nil)
参考: Create schemaExtension - Microsoft Graph v1.0
更新:
正如你在回答中提到的,“GO SDK处于预览阶段。仅供非生产使用”。因此,目前最好使用REST API调用来通过MS Graph管理资源。
英文:
I tried to reproduce the same in my environment and got below results:
When I ran below request to create extension via Graph Explorer, I got same error as you like below:
POST https://graph.microsoft.com/v1.0/users/<userID>/extensions
{
"extensionName": "dean.ext.test.1",
"theme": "dark",
"color": "purple",
"lang": "English"
}
Response:
> Note that, you can create only 2 open extensions for any directory
> resource like user, group, device etc... To confirm that, you can
> check this MS Doc on limits.
The error usually occurs if you already have 2 open extensions existing in your directory. You can make use of below MS Graph query to list open extensions on a user.
GET https://graph.microsoft.com/v1.0/users/<userID>/extensions
Response:
You can get the same results using msgraph-sdk-go
with below code:
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.UsersById("user-id").Extensions().Get(context.Background(), nil)
To delete extension from user, you can use below query by including extension name like this:
DELETE https://graph.microsoft.com/v1.0/users/<userID>/extensions/<extension_name>
Response:
You can delete open extension from user using msgraph-sdk-go
with below code:
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
graphClient.UsersById("user-id").ExtensionsById("extension-id").Delete(context.Background(), nil)
When I ran the query to list open extensions now, I got only 1 extension in response as other one is deleted successfully like below:
GET https://graph.microsoft.com/v1.0/users/<userID>/extensions
Response:
The code you are currently using to create schema extensions is creating open extensions
.
To create schema extension using msgraph-sdk-go
, once cross-check your code with below sample code:
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := graphmodels.NewSchemaExtension()
id := "domainName_schemaName"
requestBody.SetId(&id)
description := "My schema extension"
requestBody.SetDescription(&description)
targetTypes := []string {
"User",
}
requestBody.SetTargetTypes(targetTypes)
extensionSchemaProperty := graphmodels.NewExtensionSchemaProperty()
name := "theme"
extensionSchemaProperty.SetName(&name)
type := "String"
extensionSchemaProperty.SetType(&type)
extensionSchemaProperty1 := graphmodels.NewExtensionSchemaProperty()
name := "color"
extensionSchemaProperty1.SetName(&name)
type := "String"
extensionSchemaProperty1.SetType(&type)
extensionSchemaProperty2 := graphmodels.NewExtensionSchemaProperty()
name := "lang"
extensionSchemaProperty2.SetName(&name)
type := "String"
extensionSchemaProperty2.SetType(&type)
properties := []graphmodels.ExtensionSchemaPropertyable {
extensionSchemaProperty,
extensionSchemaProperty1,
extensionSchemaProperty2,
}
requestBody.SetProperties(properties)
result, err := graphClient.SchemaExtensions().Post(context.Background(), requestBody, nil)
Reference: Create schemaExtension - Microsoft Graph v1.0
UPDATE:
As mentioned in your answer, THE GO SDK IS IN PREVIEW. IT IS FOR NON-PRODUCTION USE ONLY
. So, it's better to stick with REST API calls, for now, to manage resources via MS Graph.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论