Dyota's blog

Get Power BI report URLs quickly from a workspace

Recently, I needed to rip out all of the URLs of all the reports within a Power BI workspace. Instead of right-clicking each report link and copying the URL inside, I wanted to automate this process (because I will need to do this for multiple other workspaces also). I remembered that you can run JavaScript off bookmarks in your browser, and so I wrote a script to do this.

What I'm trying to do is start at this screen (altered to remove identifying marks):

And end up with this, which is something that I can manipulate elsewhere (Power Query it into Excel, for example).

{
    "workspace": "Action Reporting",
    "url": "https://app.powerbi.com/groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/list?noSignUpCheck=1",
    "children": [
        {
            "name": "Action Report",
            "url": "https://app.powerbi.com/groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/reports/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx?noSignUpCheck=1",
            "type": "Report"
        },
        {
            "name": "Action Report",
            "url": "https://app.powerbi.com/groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/datasets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/details?noSignUpCheck=1",
            "type": "Dataset"
        },
        {
            "name": "Usage Assessment",
            "url": "https://app.powerbi.com/groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/reports/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx?noSignUpCheck=1",
            "type": "Report"
        }
    ]
}

The way I did that was with a JavaScript bookmarklet. In short, you can make a bookmark on your Favourites Bar/Bookmarks bar that you can click. Instead of putting a target URL in there, you put some JavaScript code. When you click it, it runs the code, which rips out the data from the page, composes it into JSON (as above), and puts that data onto your clipboard (so you can paste it somewhere else straight away).

The code for the bookmarklet is as follows. Just copy and paste all of this into your bookmarklet's URL, open your workspace, and click on the bookmarklet to make it go.

javascript: (() => {
    var out = {
        workspace: '',
        url: '',
        children: []
    };
    out.workspace = document.querySelectorAll('span.fluentListHeaderTitle')[0].innerText;
    out.url = window.location.href;
    var tableRows = document.querySelectorAll('div.row');
    tableRows.forEach((e) => {
        let childObject = {}, 
            nodes = e.children, 
            linkCell = nodes[1];
        let childLink = linkCell.children[0].children[0];
        childObject.name = childLink.innerText;
        childObject.url = childLink.href;
        let typeCell = nodes[2];
        let childType = typeCell.children[0];
        childObject.type = childType.innerText;
        out.children.push(childObject);
    });
    console.log(out);
    navigator.clipboard.writeText( JSON.stringify(out) );
    window.alert('Copied to your clipboard!');
})();

#javascript #powerbi #web