msgraph-sdk-go无法在用户上创建超过两个扩展。

huangapple go评论127阅读模式
英文:

msgraph-sdk-go can't create more than two extensions on a user

问题

当我尝试在用户上创建模式扩展时,如下所示:

  1. schemaExtension := graphmodels.NewSchemaExtension()
  2. additionalData := map[string]interface{}{
  3. "extensionName": "dean.ext.test.1",
  4. "theme": "dark",
  5. "color": "purple",
  6. "lang": "English",
  7. }
  8. schemaExtension.SetAdditionalData(additionalData)
  9. if result, err := client.UsersById(userId).Extensions().Post(context.Background(), schemaExtension, nil); err != nil {

我收到以下错误:

  1. Error: error status code received from the API
  2. code: BadRequest
  3. 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

  1. schemaExtension := graphmodels.NewSchemaExtension()
  2. additionalData := map[string]interface{}{
  3. "extensionName": "dean.ext.test.1",
  4. "theme": "dark",
  5. "color": "purple",
  6. "lang": "English",
  7. }
  8. schemaExtension.SetAdditionalData(additionalData)
  9. if result, err := client.UsersById(userId).Extensions().Post(context.Background(), schemaExtension, nil); err != nil {

I get this error:

  1. Error: error status code received from the API
  2. code: BadRequest
  3. 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中运行以下请求来创建扩展时,我得到了与你相同的错误,如下所示:

  1. POST https://graph.microsoft.com/v1.0/users/<userID>/extensions
  2. {
  3. "extensionName": "dean.ext.test.1",
  4. "theme": "dark",
  5. "color": "purple",
  6. "lang": "English"
  7. }

响应:

msgraph-sdk-go无法在用户上创建超过两个扩展。

请注意,你只能为任何目录资源(如用户、组、设备等)创建2个开放扩展。要确认这一点,你可以查看此MS文档中的限制。

如果你的目录中已经存在2个开放扩展,通常会出现此错误。你可以使用以下MS Graph查询列出用户的开放扩展。

  1. GET https://graph.microsoft.com/v1.0/users/<userID>/extensions

响应:

msgraph-sdk-go无法在用户上创建超过两个扩展。

你可以使用以下代码使用msgraph-sdk-go获取相同的结果:

  1. graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
  2. result, err := graphClient.UsersById("user-id").Extensions().Get(context.Background(), nil)

要从用户中删除扩展,你可以使用以下查询,其中包括扩展名称:

  1. DELETE https://graph.microsoft.com/v1.0/users/<userID>/extensions/<extension_name>

响应:

msgraph-sdk-go无法在用户上创建超过两个扩展。

你可以使用以下代码使用msgraph-sdk-go从用户中删除开放扩展:

  1. graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
  2. graphClient.UsersById("user-id").ExtensionsById("extension-id").Delete(context.Background(), nil)

当我现在运行查询以列出开放扩展时,我只得到1个扩展作为响应,因为另一个已成功删除,如下所示:

  1. GET https://graph.microsoft.com/v1.0/users/<userID>/extensions

响应:

msgraph-sdk-go无法在用户上创建超过两个扩展。

你目前使用的代码用于创建模式扩展,而不是创建开放扩展

要使用msgraph-sdk-go创建模式扩展,请与以下示例代码进行交叉检查:

  1. graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
  2. requestBody := graphmodels.NewSchemaExtension()
  3. id := "domainName_schemaName"
  4. requestBody.SetId(&id)
  5. description := "My schema extension"
  6. requestBody.SetDescription(&description)
  7. targetTypes := []string {
  8. "User",
  9. }
  10. requestBody.SetTargetTypes(targetTypes)
  11. extensionSchemaProperty := graphmodels.NewExtensionSchemaProperty()
  12. name := "theme"
  13. extensionSchemaProperty.SetName(&name)
  14. type := "String"
  15. extensionSchemaProperty.SetType(&type)
  16. extensionSchemaProperty1 := graphmodels.NewExtensionSchemaProperty()
  17. name := "color"
  18. extensionSchemaProperty1.SetName(&name)
  19. type := "String"
  20. extensionSchemaProperty1.SetType(&type)
  21. extensionSchemaProperty2 := graphmodels.NewExtensionSchemaProperty()
  22. name := "lang"
  23. extensionSchemaProperty2.SetName(&name)
  24. type := "String"
  25. extensionSchemaProperty2.SetType(&type)
  26. properties := []graphmodels.ExtensionSchemaPropertyable {
  27. extensionSchemaProperty,
  28. extensionSchemaProperty1,
  29. extensionSchemaProperty2,
  30. }
  31. requestBody.SetProperties(properties)
  32. 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:

  1. POST https://graph.microsoft.com/v1.0/users/&lt;userID&gt;/extensions
  2. {
  3. &quot;extensionName&quot;: &quot;dean.ext.test.1&quot;,
  4. &quot;theme&quot;: &quot;dark&quot;,
  5. &quot;color&quot;: &quot;purple&quot;,
  6. &quot;lang&quot;: &quot;English&quot;
  7. }

Response:

msgraph-sdk-go无法在用户上创建超过两个扩展。

> 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.

  1. GET https://graph.microsoft.com/v1.0/users/&lt;userID&gt;/extensions

Response:

msgraph-sdk-go无法在用户上创建超过两个扩展。

You can get the same results using msgraph-sdk-go with below code:

  1. graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
  2. result, err := graphClient.UsersById(&quot;user-id&quot;).Extensions().Get(context.Background(), nil)

To delete extension from user, you can use below query by including extension name like this:

  1. DELETE https://graph.microsoft.com/v1.0/users/&lt;userID&gt;/extensions/&lt;extension_name&gt;

Response:

msgraph-sdk-go无法在用户上创建超过两个扩展。

You can delete open extension from user using msgraph-sdk-go with below code:

  1. graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
  2. graphClient.UsersById(&quot;user-id&quot;).ExtensionsById(&quot;extension-id&quot;).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:

  1. GET https://graph.microsoft.com/v1.0/users/&lt;userID&gt;/extensions

Response:
msgraph-sdk-go无法在用户上创建超过两个扩展。

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:

  1. graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
  2. requestBody := graphmodels.NewSchemaExtension()
  3. id := &quot;domainName_schemaName&quot;
  4. requestBody.SetId(&amp;id)
  5. description := &quot;My schema extension&quot;
  6. requestBody.SetDescription(&amp;description)
  7. targetTypes := []string {
  8. &quot;User&quot;,
  9. }
  10. requestBody.SetTargetTypes(targetTypes)
  11. extensionSchemaProperty := graphmodels.NewExtensionSchemaProperty()
  12. name := &quot;theme&quot;
  13. extensionSchemaProperty.SetName(&amp;name)
  14. type := &quot;String&quot;
  15. extensionSchemaProperty.SetType(&amp;type)
  16. extensionSchemaProperty1 := graphmodels.NewExtensionSchemaProperty()
  17. name := &quot;color&quot;
  18. extensionSchemaProperty1.SetName(&amp;name)
  19. type := &quot;String&quot;
  20. extensionSchemaProperty1.SetType(&amp;type)
  21. extensionSchemaProperty2 := graphmodels.NewExtensionSchemaProperty()
  22. name := &quot;lang&quot;
  23. extensionSchemaProperty2.SetName(&amp;name)
  24. type := &quot;String&quot;
  25. extensionSchemaProperty2.SetType(&amp;type)
  26. properties := []graphmodels.ExtensionSchemaPropertyable {
  27. extensionSchemaProperty,
  28. extensionSchemaProperty1,
  29. extensionSchemaProperty2,
  30. }
  31. requestBody.SetProperties(properties)
  32. 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.

huangapple
  • 本文由 发表于 2023年2月27日 10:58:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定