<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Upload pbix with python in Report Server</title>
    <link>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/3272762#M30028</link>
    <description>&lt;P&gt;This code works well?&lt;/P&gt;</description>
    <pubDate>Wed, 07 Jun 2023 13:19:56 GMT</pubDate>
    <dc:creator>Cylogus</dc:creator>
    <dc:date>2023-06-07T13:19:56Z</dc:date>
    <item>
      <title>Upload pbix with python</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/2659484#M25017</link>
      <description>&lt;P&gt;Hi! I have Power BI Report Server May 2022 and i try to upload pbix-file use api. I write this code:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from asyncio.windows_events import NULL
from requests import request
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
import json
from requests_ntlm import HttpNtlmAuth
from urllib3.exceptions import InsecureRequestWarning
from urllib3 import disable_warnings

disable_warnings(InsecureRequestWarning)

urlpbirs = "https://pbirs.ontoso.com/reports/api/v2.0/PowerBIReports"
file = open("testapi.pbix", "rb")
file_location = "testapi.pbix"
files = {'value': (None, open(file_location,
                   'rb'), 'multipart/form-data')}
mp_encoder = MultipartEncoder(fields=files)

headers = {
    'accept': 'application/json',
    # Already added when you pass json= but not when you pass data=
    # 'Content-Type': 'application/json',
}

json_data = {
    'Name': 'test',
    'Description': 'test api with python',
    'Type': 'PowerBIReport',
    'Hidden': False,
    'IsFavorite': False,
    'ContentType': NULL,
    'Content': '',
    'HasDataSources': True,
    'Path': '/BI Test'
}

r = requests.post(url=urlpbirs, data=mp_encoder, auth=HttpNtlmAuth(
    'user', 'pass'), verify=False, headers=headers, json=json_data)

But it doesn't work&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 14:31:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/2659484#M25017</guid>
      <dc:creator>vaalyushin</dc:creator>
      <dc:date>2022-07-25T14:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Upload pbix with python</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/2660555#M25023</link>
      <description>&lt;P&gt;I'm pretty sure you need to use the CatalogItems endpoint to upload reports.&lt;/P&gt;
&lt;P&gt;eg.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from asyncio.windows_events import NULL
from requests import request
import requests
import base64
import json
from requests_negotiate_sspi import HttpNegotiateAuth
from urllib3.exceptions import InsecureRequestWarning
from urllib3 import disable_warnings

disable_warnings(InsecureRequestWarning)

urlpbirs = "http://localhost/reports/api/v2.0/CatalogItems"
file = "C:/temp/test.pbix"
file_text = open(file, 'rb')
file_read = file_text.read()
file_encode = base64.b64encode(file_read).decode('utf-8')

headers = {
    'accept': 'application/json',
    'Content-Type': 'application/json',
}

json_data = {
    'Name': 'BI Test 2',
    '@odata.type': '#Model.PowerBIReport',
    'ContentType': '',
    'Content': file_encode,
    'Path': '/BI Test 2'
}

r = requests.post(url=urlpbirs,  auth=HttpNegotiateAuth(), verify=False, headers=headers, json=json_data)
print(r)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Jul 2022 02:29:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/2660555#M25023</guid>
      <dc:creator>d_gosbell</dc:creator>
      <dc:date>2022-07-26T02:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Upload pbix with python</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/3272762#M30028</link>
      <description>&lt;P&gt;This code works well?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 13:19:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Upload-pbix-with-python/m-p/3272762#M30028</guid>
      <dc:creator>Cylogus</dc:creator>
      <dc:date>2023-06-07T13:19:56Z</dc:date>
    </item>
  </channel>
</rss>

