Forum Discussion

Jeanxyz's avatar
Jeanxyz
Icon for Power Participant rankPower Participant
1 year ago
Solved

can't get semantic model definition via API call

I'm learning semantic link and encounter an error with the code below:

'''''

import pandas as pd
import sempy.fabric as fabric
import base64
import json
import requests
import fnmatch

client = fabric.FabricRestClient()

#get the default workspace id of the notebook
workspaceId = fabric.get_workspace_id()
items = fabric.list_items(workspace=workspaceId)

itemId = items[items['Type']=="Report"].iloc[0].Id

response = client.post(f"/v1/workspaces/{workspaceId}/items/{itemId}/getDefinition")
print(f"first report in workspace is:'{itemId}'")
jsonParts= response.json()['definition']['parts']
pd.set_option('display.max_colwidth',100)
df_parts=pd.json_normalize(jsonParts)
df_parts

# check response from API call
print(f"Response Status Code: {response.status_code}")
print(f"Response Text: {response.text}")
''''
the printout returns status code: 202. Does anyone know the reason? I am admin of the Fabric workspace where I try to make an API call and the printout of itemId shows there are valid reports.
  • Hi Jeanxyz,

    Thank you for reaching out to the Microsoft Fabric Forum Community.

     

    The 202 Accepted status means your request to retrieve the semantic model definition has been received and is being processed asynchronously. It is not an error, but a confirmation that the process is in progress.

    Please consider the following steps:

    • After receiving a 202 Accepted response, the API usually provides a polling URL in the response body. This URL is used to monitor the status of your request, indicating whether it’s still processing, completed, or encountered an issue. Make sure to capture and use it for tracking progress.
    • You can regularly query the polling URL to check the status of your request, which could be InProgress, Succeeded, Failed, or Cancelled. If it shows InProgress, wait before querying again. Some responses might include a Retry-After header, indicating how long to wait.
    • Once the status changes to Succeeded, the response will provide a download URL. Use this URL to download the semantic model definition. If the downloadUrl is still null, keep polling until it becomes available.

    If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

     

    Thank you.

11 Replies

    • Jeanxyz's avatar
      Jeanxyz
      Icon for Power Participant rankPower Participant

      How can I see the result when the request is accepted? I used sleep() method, but still don't get results. My code above is complete, it will work on any Fabric notebook. 

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

        the 202 response shoud include a polling URL that you can use to probe the status of the request, and a download URL when the request is complete

         

  • v-saisrao-msft's avatar
    v-saisrao-msft
    Icon for Community Support rankCommunity Support

    Hi Jeanxyz,


    I wanted to check if you had the opportunity to review the information provided by lbendlin. Please feel free to contact us if you have any further questions. If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


    Thank you.