Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

60 Days of Data Days! Live and on-demand sessions, challenges, study groups and more! And it's all FREE!. Join now. Learn more

Reply
Kuladeep
Advocate II
Advocate II

Fabric REST report/getDefinition Endpoint is not returning definition

Hallo Fabric Community,

 

Fabric REST `https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/reports/{reportId}/getDefinition` endpoint is not returning any definition. It is returning a json object like this `
{'status': 'Succeeded',
 'createdTimeUtc': '2026-05-22T15:47:35.2651275',
 'lastUpdatedTimeUtc': '2026-05-22T15:47:35.4583119',
 'percentComplete': 100,
 'error': None}
`
I am looking to extract `"path": "report.json"` from the `definition` as showed in the official Documentation

my code:
def getReportDefinition(workspaceId: str, reportId: str, headers: dict) -> dict:
    """
    Fetch report definition, handling both 200 (sync) and 202 (async/polling).
    Returns the parsed definition dict.
    """
    _url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/reports/{reportId}/getDefinition"
    _response = requests.post(_url, headers=headers)

    # --- Synchronous response ---
    if _response.status_code == 200:
        return _response.json()

    # --- Asynchronous response: poll until complete ---
    if _response.status_code == 202:
        _operationUrl = _response.headers.get("Location")
        _retryAfter   = int(_response.headers.get("Retry-After", 10))

        if not _operationUrl:
            raise ValueError("202 received but no Location header found.")

        return _pollOperation(_operationUrl, _retryAfter, headers)

    _response.raise_for_status()


def _pollOperation(operationUrl: str, retryAfter: int, headers: dict) -> dict:
    """
    Poll a Fabric long-running operation until it succeeds or fails.
    Returns the final result payload.
    """
    MAX_POLL_ATTEMPTS = 20

    for _attempt in range(1, MAX_POLL_ATTEMPTS + 1):
        print(f"  Polling attempt {_attempt}/{MAX_POLL_ATTEMPTS} — waiting {retryAfter}s ...")
        time.sleep(retryAfter)

        _pollResponse = requests.get(operationUrl, headers=headers)
        _pollResponse.raise_for_status()

        _pollJson = _pollResponse.json()
        _status   = _pollJson.get("status", "").lower()

        if _status == "succeeded":
            # The completed result is either inline or needs a separate GET
            _resultUrl = _pollJson.get("createdTimeUtc") and _pollJson.get("percentComplete") and \
                         _pollJson.get("resourceLocation")
            
            if _resultUrl:
                # Some operations put the result at resourceLocation
                _resultResponse = requests.get(_resultUrl, headers=headers)
                _resultResponse.raise_for_status()
                return _resultResponse.json()
            
            # Result is embedded directly in the poll response
            return _pollJson

        if _status in ("failed", "cancelled"):
            _error = _pollJson.get("error", {})
            raise RuntimeError(
                f"Operation {_status}: [{_error.get('errorCode')}] {_error.get('message')}"
            )

        # Still running — respect a new Retry-After if provided
        retryAfter = int(_pollResponse.headers.get("Retry-After", retryAfter))

    raise TimeoutError(f"Operation did not complete after {MAX_POLL_ATTEMPTS} polling attempts.")


def decodeReportJson(definition: dict) -> dict:
    """
    Find report.json in definition parts, decode its InlineBase64 payload,
    and return the parsed JSON content.
    """
    _parts = definition.get("definition", {}).get("parts", [])

    for _part in _parts:
        if _part.get("path") == "report.json" and _part.get("payloadType") == "InlineBase64":
            _decoded = base64.b64decode(_part["payload"]).decode("utf-8")
            return json.loads(_decoded)

    raise ValueError("report.json not found in definition parts.")


# --- Main ---
WORKSPACE_ID = workspaceId
REPORT_ID    = reportId

_definition  = getReportDefinition(WORKSPACE_ID, REPORT_ID, CONTRIBUTOR_SP_HEADERS_FABRIC)

 

1 ACCEPTED SOLUTION
apturlov
Super User
Super User

@Kuladeep getDefinition request is a Long Running Operation in Fabric REST API and it's a 3-step process:

 

  1. POST for getDefinition: it returns a 202 accepted with a link for the status poll in the location header.
  2.  GET status: it returns 200 with the status - as you correctly showed in your post above. DOES NOT return the result yet, but the result link in the location.
  3. GET result: a url for this in the status location header: returns the result in this format:

{
  "definition": {
    "parts": [
      {
        "path": "report.json",
        "payload": "QmFzZTY0U3RyaW5n",
        "payloadType": "InlineBase64"
      },
      {
        "path": "definition.pbir",
        "payload": "QW5vdGhlckJhc2U2NFN0cmluZw",
        "payloadType": "InlineBase64"
      },
      {
        "path": ".platform",
        "payload": "ZG90UGxhdGZvcm1CYXNlNjRTdHJpbmc=",
        "payloadType": "InlineBase64"
      }
    ]
  }
}


In your code above you do not extract the result URL correctly from the status response location header. You should extrat the result URL from the location header of the status response when percentComplete == "100". Do it like this:

 _resultUrl = _response.headers.get("Location")

 

I tested in my environment and the process works correctly and returns the report definition in a form (obfuscated):

{
  "definition": {
    "format": "PBIR-Legacy",
    "parts": [
      {
        "path": "definition.pbir",
        "payload": "ewogIC...",
        "payloadType": "InlineBase64"
      },
      {
        "path": "StaticResources/SharedResources/BaseThemes/CYxxxxxx.json",
        "payload": "ewogICJu...",
        "payloadType": "InlineBase64"
      },
      {
        "path": "report.json",
        "payload": "ewogICJjb25maW...",
        "payloadType": "InlineBase64"
      },
      {
        "path": ".platform",
        "payload": "ewo...",
        "payloadType": "InlineBase64"
      }
    ]
  }
}


Hope you find this helpful. In such case give it kudos and accept as a solution to help other community members.

View solution in original post

1 REPLY 1
apturlov
Super User
Super User

@Kuladeep getDefinition request is a Long Running Operation in Fabric REST API and it's a 3-step process:

 

  1. POST for getDefinition: it returns a 202 accepted with a link for the status poll in the location header.
  2.  GET status: it returns 200 with the status - as you correctly showed in your post above. DOES NOT return the result yet, but the result link in the location.
  3. GET result: a url for this in the status location header: returns the result in this format:

{
  "definition": {
    "parts": [
      {
        "path": "report.json",
        "payload": "QmFzZTY0U3RyaW5n",
        "payloadType": "InlineBase64"
      },
      {
        "path": "definition.pbir",
        "payload": "QW5vdGhlckJhc2U2NFN0cmluZw",
        "payloadType": "InlineBase64"
      },
      {
        "path": ".platform",
        "payload": "ZG90UGxhdGZvcm1CYXNlNjRTdHJpbmc=",
        "payloadType": "InlineBase64"
      }
    ]
  }
}


In your code above you do not extract the result URL correctly from the status response location header. You should extrat the result URL from the location header of the status response when percentComplete == "100". Do it like this:

 _resultUrl = _response.headers.get("Location")

 

I tested in my environment and the process works correctly and returns the report definition in a form (obfuscated):

{
  "definition": {
    "format": "PBIR-Legacy",
    "parts": [
      {
        "path": "definition.pbir",
        "payload": "ewogIC...",
        "payloadType": "InlineBase64"
      },
      {
        "path": "StaticResources/SharedResources/BaseThemes/CYxxxxxx.json",
        "payload": "ewogICJu...",
        "payloadType": "InlineBase64"
      },
      {
        "path": "report.json",
        "payload": "ewogICJjb25maW...",
        "payloadType": "InlineBase64"
      },
      {
        "path": ".platform",
        "payload": "ewo...",
        "payloadType": "InlineBase64"
      }
    ]
  }
}


Hope you find this helpful. In such case give it kudos and accept as a solution to help other community members.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.