skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

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

    enter image description here

    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:

    enter image description here

    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:

    enter image description here

    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:
    enter image description here

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search