Click here to Skip to main content
15,887,404 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Failed to create report. Error: b'{\r\n  "error":{\r\n    "code":"","message":"No HTTP resource was found that matches the request URI \'http://wabi-india-central-a-primary-redirect.analysis.windows.net/v1.0/myorg/groups/me/reports\'."\r\n  }\r\n}'
None

this is the error I'm getting

What I have tried:

import requests
import json

# Set your Power BI REST API endpoint URLs
base_url = "https://api.powerbi.com/v1.0/myorg"
reports_url = f"{base_url}/groups/{group_id}/reports"

# Set your authentication token
access_token = "YOUR_ACCESS_TOKEN"

# Set the group ID where the report will be created
group_id = "YOUR_GROUP_ID"

# Create a report definition
report_definition = {
    "name": "My Report",
    "datasetId": "EXISTING_DATASET_ID"
}

# Create the report in the group
def create_report():
    create_report_url = reports_url
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json"
    }
    payload = {
        "name": report_definition["name"],
        "datasetId": report_definition["datasetId"]
    }
    response = requests.post(create_report_url, headers=headers, json=payload)
    if response.status_code == 201:
        report_id = response.json()["id"]
        print("Report created successfully. ID:", report_id)
        return report_id
    else:
        print("Failed to create report. Error:", response.content)
        return None

# Run the function to create the report
create_report()


This is what i have tried
Posted
Updated 14-Jun-23 1:49am
Comments
Richard MacCutchan 14-Jun-23 7:58am    
You need to check that the URI you are using is the correct one for the API.

1 solution

You have an invalid character - 'f'
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}

change to:
headers = {
    "Authorization": "Bearer {access_token}",
    "Content-Type": "application/json"
}


The error message is the clue:
No HTTP resource was found that matches the request URI

This is saying that the data does not exist at that address. Check that the URL is correct. Also, see if there is a response code, that can also indicate what the issue is - could be that there is an authorization issue.
 
Share this answer
 
v2
Comments
Richard MacCutchan 14-Jun-23 7:56am    
No, that is the correct way to specify inline formatting in Python.
Graeme_Grant 14-Jun-23 8:00am    
Ah, wasn't sure which language he was using. It looked out of place.
Richard MacCutchan 14-Jun-23 8:19am    
Didn't they send you one of the CodeProject Crystal Balls? :)
Graeme_Grant 14-Jun-23 8:24am    
ROFL ... I missed out last Xmas, maybe this year. Python is on my list of languages to learn, just have to find the time...
Dave Kreskowiak 14-Jun-23 9:35am    
Mine was arrived but shattered during shipping. Chris has yet to send me another one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900