Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 months ago
Solved

Power Bi Fabric scope issue

Hi Everyone,

I am trying to fetch the data from the semantic model using the fabric semantic model  api , for authentication  i am using  this scope=["https://api.fabric.microsoft.com/.default"], and sematic model api, url=https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/semanticModels/{model_id}/getdefinition.

But it is giving me this error
Trigger Status: 404
❌ No operation-location returned
{"requestId":"3268bb1a-ea65-4807-b374-5ee81a61ba47","errorCode":"EntityNotFound","message":"The requested resource could not be found"}.

Just want to verify my scope url is correct or not?


  • This is correct, because the getDefinition API is a long-running operation that does not directly return the result. You have to create code keep polling for the result to be ready. What you can do is use Semantic-Link (SemPy) library from Microsoft for Fabric to call the API, wait for the results to be ready and then fetch the results.

     

    import sempy.fabric as fabric
    
    workspace_id = "<YOUR_WORKSPACE_ID>"
    semantic_model_id = "<YOUR_SEMANTIC_MODEL_ID>"
    
    client = fabric.FabricRestClient()
    
    resp = client.post(f"/v1/workspaces/{workspace_id}/semanticModels/{semantic_model_id}/getDefinition")
    
    if resp.status_code == 202:
        # Get operation id and poll via SemPy client
        op_id = resp.headers.get("x-ms-operation-id") or resp.headers.get("Location").split("/")[-1]
    
        # Poll until it finishes
        while True:
            op = client.get(f"/v1/operations/{op_id}").json()
            status = op.get("status")
            if status in ("Succeeded", "Failed", "Cancelled"):
                if status != "Succeeded":
                    raise RuntimeError(f"GetDefinition failed: {op}")
                break
    
        # Fetch the final result (the actual definition payload)
        result = client.get(f"/v1/workspaces/{workspace_id}/operations/{op_id}/result").json()
    else:
        # Sometimes you may get 200 with the definition inline
        result = resp.json()

     

    Hope this helps. If so, please give a Kudos 👍 and mark as Accepted Solution ✔️.

7 Replies

  • Hi Anonymous, according to the error message "The requested resource could not be found" you are already authenticated, but the Fabric resource was not found. Otherwise you would have gotten a different error message. You might want to check you workspaceId or semanticModelId of they are correct.

     

    As you probably already know, you can can easily check your Id's on the API reference page.

     

    Hope this helps. If so, please give a Kudos 👍 or mark as Accepted Solution ✔️.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Where i can get those id

      • nielsvdc's avatar
        nielsvdc
        Icon for Super User rankSuper User

        When you click on your semantic model in your browser, the URL for the semantic model looks like this: 

        https://app.powerbi.com/groups/3e0615b4-bde4-4270-938e-5271027fa82e/datasets/6774f98b-67db-4253-b33d-1e23a59d0a88/details
         
        The first Id behind "groups/" is your workspace Id. The second Id behind "datasets/" is your semantic model Id. This URL construct is the same for any other Fabric item.
         
        Hope this helps. If so, please give a Kudos 👍 or mark as Accepted Solution ✔️.