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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Kuladeep
Advocate I
Advocate I

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
Continued Contributor
Continued Contributor

@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
Continued Contributor
Continued Contributor

@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
April Fabric Update Carousel

Fabric Monthly Update - April 2026

Check out the April 2026 Fabric update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.