Share via

Fabric Semantic Model - Add member to Role through API

Perez Lemme, Ignacio 0 Reputation points
2025-10-03T20:36:00.5133333+00:00

Hi all,

I am trying to develop a C# integration with Microsoft Fabric to generate semantic models programmatically (https://learn.microsoft.com/en-us/rest/api/fabric/semanticmodel/items/create-semantic-model). So far, I was able to create the semantic model connections, tables, measures, and even roles.

However, I did not find a way to include members within my role definition. Attached, I've included my current TMSL definition for the role, which is pretty much the same that if I add the member manually from the UI.

Is there any possible way to automate this?

Regards,

Ignacio

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Starry Night 625 Reputation points
    2025-10-09T05:50:23.47+00:00

    A semantic model in Microsoft Fabric acts as a business-friendly layer over raw data, enabling meaningful insights and seamless integration with tools like Power BI. Below is a step-by-step guide to creating a semantic model using the Fabric API.

    Using the Fabric REST API

    Step 1: Prerequisites

    • Ensure you have Contributor permissions in the workspace.
    • Obtain the required API scopes: SemanticModel.ReadWrite.All or Item.ReadWrite.All.
    • Verify that your Microsoft Fabric license supports semantic modeling.

    Step 2: Construct the API Request

    Use the following endpoint to create a semantic model:

    POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/semanticModels
    

    Replace {workspaceId} with your workspace's unique ID.

    Step 3: Define the Request Body

    Provide details for the semantic model, including its definition and metadata:

    {
    "displayName": "SemanticModel 1",
    "description": "A semantic model description.",
    "definition": {
    "parts": [
    {
    "path": "model.bim",
    "payload": "ew0KICAiY29tcGF0a..GVzIjogWyBdDQogIH0NCn0=",
    "payloadType": "InlineBase64"
    }
    ]
    }
    }
    
    
    • displayName: Name of the semantic model.
    • definition: Base64-encoded payload defining the model structure.

    Step 4: Execute the Request

    Send the request using tools like cURL, Postman, or any HTTP client:

    curl -X POST \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    -H "Content-Type: application/json" \
    -d @request_body.json \
    "https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/semanticModels"
    
    

    Step 5: Validate Response

    • 201 Created response confirms successful creation.
    • 202 Accepted response indicates that provisioning is in progress. Use the Location header to track status.

    Best Practices

    • Use meaningful names and descriptions for easier identification.
    • Ensure all required tables or data sources are properly linked before creating the model.
    • Regularly update and maintain semantic models to reflect changes in data structures.

    By following these steps, you can efficiently create and manage semantic models in Microsoft Fabric, enabling robust analytics and reporting capabilities.

    Was this answer helpful?

    0 comments No comments

  2. Adiba Khan 2,345 Reputation points Microsoft External Staff
    2025-10-07T05:43:02.8633333+00:00

    Thanks for reaching out. Here are some recommended solutions:

    1.      Use the Power BI REST API to Post Dataset Users

    Since fabric semantic models inherit much of their structure and management from Power BI REST API is still the standard way to manage member assignments to semantic model roles.

    The relevant API calls are:

    ·         POST Datasets- POST Dataset User (or Post Dataset User In Group): This API adds a specified user, group, or service principal to the semantic model’s permissions. This is the API to use for assigning users/groups to the semantic model roles you’ve created.

    o   Interface: POST https://api.powerbi.com/v1.0/myorg/datasets/{datasetid}/users (for use the group/workspace version).

    o   Required Payload: You will need to specify the principal type  (User, Group, App), the identifier and the DatasetUserAccessRight which includes the semantic model role name.

    o   C# implementation: you would use an HttpClient in your C# application to make this authenticated POST request to the Power BI REST API endpoint after your Semantic Model has been created in fabric.

    2.      Use XMLA Endpoint (for Advanced TMSL/C# AMO)

    If you require a pure TMSL or a more direct, lower-level control, the XMLA Endpoint is the traditional path for managing Analysis Services objects, including semantic model roles and membership.

    ·         Method: You would connect to the Fabric workspace’s XMLS endpoint using a C# application leveraging the Analysis Services management objects (AMO) library.

    ·         Action: You can execute a TMSL CreateOrReplace command that includes the full members definition for the role. This method gives you the flexibility to manage the entire semantic model metadata, including role membership, programmatically.

    3.      Leverage Dynamics RLS

    If the goal is to enforce Row-level Security (RLS), a common and scalable pattern is to avoid assigning individual users to roles entirely and instead implement Dynamic RLS.

    ·         Mechanism:

    o   Create a single RLS role (e.g., “All Users”) in your semantic model and assign all users (or a large security group) to it.

    o   In the role’s DAX filter expression, use the USERPRINCIPALNAME() function.

    o   Create a lookup table (or security table) in your semantic model that maps User Principal Names (UPNs) to their allowed data (e.g., UPN to Region ID)

    ·         Automation: You can automate the updating of this lookup table via a Fabric Notebook or another ETL process. This is much easier to manage than constantly updating role assignments via API calls.

    Summary of Automation Methods:

    o   Direct Assignment: best for explicitly assigning individual groups to RLS roles.

    Tool/API: PowerBI REST API (Post Dataset User)

    C# Path: HttpClient POST Request

    o   Advanced Metadata: best for full control via raw TMSL/AXML

    Tool/API: XMLA Endpoint

    C# Path: C# AMO Library

    o   Scalable RLS: Best for Large , frequently changing user base

    Tool/API: Dynamic RLS +Fabric notebooks/ETL

    C# Path: C# updates to data source (optional)

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.