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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HeetParkhiya
Regular Visitor

Fabric Create report API

Hello Team,

I am trying to create report using the fabric rest api and it throws me the "Content provider provided invalid package content stream".

Here is my report.json schema :

{
        "themeCollection": {
            "baseTheme": {
            "name": "Default",
            "type": "SharedResources",
            "reportVersionAtImport": {
                "visual": "3.0.0",
                "page": "3.0.0",
                "report": "3.0.0"
            }
        }
     }
    }

definition.pbir schema:

{
    "version": "2.0",
    "datasetReference": {
      "byConnection": {
        "connectionString": "semanticModelId=valid-guid"
      }
     }
    }

both of the above json are getting encoded and being passed in the request body and I would like some help on it, where the error is occuring report.json or definition.pbir syntax? how do I resolve it?
{
        "displayName": report_name,
        "definition": {
            "parts": [
                {
                    "path": "report.json",
                    "payload": b64(report_json),
                    "payloadType": "InlineBase64"
                },
                {
                    "path": "definition.pbir",
                    "payload": b64(definition_pbir),
                    "payloadType": "InlineBase64"
                }
            ]
        }
    }
8 REPLIES 8
deborshi_nag
Advocate V
Advocate V

Hello @HeetParkhiya 

 

I have been able to use the Fabric REST endpoint to create a sample report. I have used the modern PBIR format.  

 

Here is the payload for the endpoint - 

 

{
  "definition": {
    "parts": [
      {
        "path": "definition.pbir",
        "payload": "<base64>",
        "payloadType": "InlineBase64"
      },
      {
        "path": "definition/report.json",
        "payload": "<base64>",
        "payloadType": "InlineBase64"
      },
      {
        "path": "definition/version.json",
        "payload": "<base64>",
        "payloadType": "InlineBase64"
      },
      {
        "path": "definition/pages/pages.json",
        "payload": "<base64>",
        "payloadType": "InlineBase64"
      },
      {
        "path": ".platform",
        "payload": "<base64>",
        "payloadType": "InlineBase64"
      },
      {
        "path": "definition/pages/d20e46cf39e616b15188/page.json",
        "payload": "<base64>",
        "payloadType": "InlineBase64"
      }
    ]
  }
}

 

I have used Power BI Desktop to create the template report.json and definition.pbir files. 

 

Hope this helps - please appreciate leaving a Kudos or accepting as a Solution

deborshi_nag
Advocate V
Advocate V

Hello @HeetParkhiya 

 

Don't you need a .platform in your definition in the request body? 

 

{
        "path": ".platform",
        "payload": "ZG90UGxhdGZvcm1CYXNlNjRTdHJpbmc=",
        "payloadType": "InlineBase64"
      }

 

Can you try using Power BI Desktop to create the report.json, definition.pbir and .platform files first before trying to upload using the REST endpoint?

Hello @deborshi_nag

I am going with the PBIR-Legacy format and It does not specify to use the .platform files? Also do you have a fully working payload that I can test/use or just generate a template from the power bi and use it to test it?

https://learn.microsoft.com/en-us/rest/api/fabric/articles/item-management/definitions/report-defini... 


@HeetParkhiya 

 

Here's a python code you can use to generate the payload. Create a legacy format PBIR file using Power BI Desktop first! The payload will be written to the root directory. 

 

You can use the "Try It" button and paste the payload in the below link using your Fabric/Power BI workspace GUID.

 

Items - Create Report - REST API (Report) | Microsoft Learn 

 

#!/usr/bin/env python3
# PBIR-Legacy payload validator + builder (Fabric Items API - Reports)

import os, sys, json, base64

# --- CONFIG: Point to your PBIR-legacy project root (contains definition.pbir and report.json) ---
PBIP_ROOT = r"C:\Legacy Report\legacy_report.Report"   # <-- UPDATE THIS to your legacy project folder

INCLUDE_PLATFORM = True                     # include .platform if present
INCLUDE_REGISTERED_RESOURCES = True         # include files under RegisteredResources/**
INCLUDE_STATIC_RESOURCES = True             # include files under StaticResources/**

# Optionally constrain resource file extensions to reduce payload bloat
RESOURCE_EXTENSIONS = {".json", ".jpg", ".jpeg", ".png", ".gif", ".pbiviz"}

def die(msg):
    print(f"ERROR: {msg}", file=sys.stderr)
    sys.exit(1)

def is_file(rel):
    return os.path.isfile(os.path.join(PBIP_ROOT, rel))

def must_file(rel):
    p = os.path.join(PBIP_ROOT, rel)
    if not os.path.isfile(p):
        die(f"Missing required file: {rel} at {p}")
    return rel

def b64(rel):
    with open(os.path.join(PBIP_ROOT, rel), "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")

def add_part(parts, rel):
    # Enforce forward slashes in 'path' for the API
    api_rel = rel.replace("\\", "/")
    parts.append({"path": api_rel, "payload": b64(rel), "payloadType": "InlineBase64"})
    print(f" + Added part: {api_rel}")

def walk_resources(root_rel, parts):
    """Add resource files beneath 'root_rel' (e.g., RegisteredResources or StaticResources)."""
    root_abs = os.path.join(PBIP_ROOT, root_rel)
    if not os.path.isdir(root_abs):
        return
    for dirpath, _, filenames in os.walk(root_abs):
        for name in filenames:
            ext = os.path.splitext(name)[1].lower()
            if RESOURCE_EXTENSIONS and ext not in RESOURCE_EXTENSIONS:
                continue
            # Build relative path that mirrors the on-disk tree from PBIP_ROOT
            rel_path = os.path.relpath(os.path.join(dirpath, name), PBIP_ROOT)
            add_part(parts, rel_path)

# --- Validate PBIR-legacy layout ---
print(f"Using PBIP_ROOT: {PBIP_ROOT}")
must_file("definition.pbir")
must_file("report.json")

# --- Build parts ---
parts = []
print("\nAdding PBIR-legacy core parts:")
add_part(parts, "definition.pbir")
add_part(parts, "report.json")

# Optional .platform
if INCLUDE_PLATFORM and is_file(".platform"):
    add_part(parts, ".platform")

# Optional RegisteredResources/** and StaticResources/**
# (themes, images, private custom visuals, etc.)
if INCLUDE_REGISTERED_RESOURCES:
    print("\nScanning RegisteredResources/**")
    walk_resources("RegisteredResources", parts)

if INCLUDE_STATIC_RESOURCES:
    print("\nScanning StaticResources/**")
    walk_resources("StaticResources", parts)

# --- Print summary and write payload.json ---
print("\nSummary:")
print(f" Total parts: {len(parts)}")
present_paths = [p["path"] for p in parts]
print(" Paths included:")
for p in present_paths:
    print("  -", p)

# Confirm the specific required paths exist in parts
if "definition.pbir" not in present_paths:
    die("CRITICAL: 'definition.pbir' was not included in parts[]")
if "report.json" not in present_paths:
    die("CRITICAL: 'report.json' was not included in parts[]")

payload = {"definition": {"parts": parts}}
out_path = os.path.join(PBIP_ROOT, "payload.json")
with open(out_path, "w", encoding="utf-8") as f:
    json.dump(payload, f, indent=2)
print(f"\nPayload written to: {out_path}")

 

Hope this helps - please appreciate leaving a Kudos or accepting as a Solution!  

Vinodh247
Solution Sage
Solution Sage

The error is coming from invalid file contents not how you wrapped the request. Your definition.pbir schema URL seems incomplete and must point to the full schema.json, otherwise validation fails. Your report.json is also too minimal; fabric requires at least stub properties like pages and config, not just themeCollection. Finally, the dataset reference must point to a real semantic model in the same workspace. Fix the schema URL, add the missing top-level sections to report.json, and verify the datasetID. Once those are valid UTF8 JSON strings and base64 encoded correctly, the REST create call succeeds.

 


Please 'Kudos' and 'Accept as Solution' if this answered your query.

Regards,
Vinodh
Microsoft MVP [Fabric]

@Vinodh247 can you provide me the full schema for the definiation.pbir? because the docs provides the example of the only below provided json.

https://learn.microsoft.com/en-us/power-bi/developer/projects/projects-report?tabs=v2%2Cdesktop#defi...

{
    "version""2.0",
    "datasetReference": {
      "byConnection": {
        "connectionString""semanticModelId=valid-guid"
      }
     }
    }

There is no published full schema document listing every property for definition.pbir that you can download from microsoft; what exists is the JSON Schema endpoint URL (use VS Code for validation), and the effective expected content is extremely simple: essentially only these keys matter for REST deployment. What you need is this canonical structure (use this exact JSON with the correct schema URL and semantic model ID):

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/report/definitionProperties/2.0.0/schema.json",
  "version": "4.0",
  "datasetReference": {
    "byConnection": {
      "connectionString": "semanticmodelid=[SemanticModelId]"
    }
  }
}

replace [SemanticModelId] with your valid semantic model GUID

the schema expects:

  • $schema pointing to the published schema JSON (not truncated)

  • version (4.0 is typical for reports deployed from modern PBI Desktop/Fabric)

  • datasetReference.byConnection.connectionString with semanticmodelid=GUID

Other than those keys, the RESTAPI will reject anything extra or incomplete because it strictly validates against that schema. You cannot include additional keys outside what the schema defines for definition.pbir when creating via REST.  If you need to explore every property the schema defines, you can paste the $schema URL into a code editor with JSON Schema support to see the full fields (this is the source of truth)

HTH!


Please 'Kudos' and 'Accept as Solution' if this answered your query.

Regards,
Vinodh
Microsoft MVP [Fabric]

Hello, I have changed the definition.pbir and report.json, It is throwing the error " Content provider provided invalid package content stream"

I have changed or reverted the report.json to 1.0.0 schema version because many people are facing issues with the latest version.

report.json

{ "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/report/definition/report/1.0.0/schema.json", "layoutOptimization": "None", "themeCollection": { "baseTheme": { "name": "Default", "reportVersionAtImport": "1.0.0", "type": "SharedResources" } } } 
definition.pbir
{
        "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/report/definitionProperties/2.0.0/schema.json",
        "version": "4.0",
        "datasetReference": {
            "byConnection": {
            "connectionString": "semanticmodelid=9e2b0971-7e50-4758-9241-310a603e7430"
            }
        }
    }

 

 

Helpful resources

Announcements
December Fabric Update Carousel

Fabric Monthly Update - December 2025

Check out the December 2025 Fabric Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.