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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ForTheQuestions
New Member

Subscriptions: Programmatically creating subscriptions

Does anyone know a way to programmatically create subscriptions? We already have the azure groups we just don't want to have to go through and create all the (50-100) subscriptions if there is a way to automate this. 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @ForTheQuestions ,

Base on my research, I didn't find a suitable way to programmatically create subscriptions. You can try using the method in the link below as a workaround to create a subscription.

1. Power Bi subscriptions by Powershell

You cannot programmatically trigger e-mail subscriptions. They are running according their schedule. But you can use Export to File API to export the report to a PDF file (or some other supported file type) and send it to someone. This means that the workspace must be attached to a dedicated capacity (Power BI Premium P SKU, Power BI Premium EM SKU or Power BI Embedded A SKU, and probably Premium per user) and you should maintain the list of "subscribers" on your own.

Here is some PowerShell code, which uses Power BI Management CmdLets, which will export a report to PDF and send it by e-mail. You need to edit the parameters in the beginning of the code, like report ID, workspace ID, credentials, recipients, etc.

#############################################################
# Install-Module -Name MicrosoftPowerBIMgmt
# Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser
#############################################################
Import-Module MicrosoftPowerBIMgmt
....
#############################################################
# E-mail settings
#############################################################
$emailSmtpServer = "smtp.office365.com"
$emailSmtpServerPort = 587
$emailTo = $username
$emailSubject = "Here is your report"
$emailBodyHtml = "Please find <b>your report</b> attached here."
$emailUser = "account@example.com"
$emailPassword = "SuperStrongPassword"
$emailFrom = $emailUser
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential
$settings = @{ includeHiddenPages = $false; locale = "en-us" }
$powerBIReportConfiguration = @{ settings = $settings }
$export_body = @{ format = $format; powerBIReportConfiguration = $powerBIReportConfiguration }
#'{
#  format: "$format",
#  powerBIReportConfiguration: { settings: { includeHiddenPages: false, locale: "en-us" } }
#}'
.....

2. PowerAutomate

Export and email a Power BI report with Power Automate

Schedule, Export and Email Power BI Reports using Power Automate

yingyinr_0-1647248497961.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @ForTheQuestions ,

Base on my research, I didn't find a suitable way to programmatically create subscriptions. You can try using the method in the link below as a workaround to create a subscription.

1. Power Bi subscriptions by Powershell

You cannot programmatically trigger e-mail subscriptions. They are running according their schedule. But you can use Export to File API to export the report to a PDF file (or some other supported file type) and send it to someone. This means that the workspace must be attached to a dedicated capacity (Power BI Premium P SKU, Power BI Premium EM SKU or Power BI Embedded A SKU, and probably Premium per user) and you should maintain the list of "subscribers" on your own.

Here is some PowerShell code, which uses Power BI Management CmdLets, which will export a report to PDF and send it by e-mail. You need to edit the parameters in the beginning of the code, like report ID, workspace ID, credentials, recipients, etc.

#############################################################
# Install-Module -Name MicrosoftPowerBIMgmt
# Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser
#############################################################
Import-Module MicrosoftPowerBIMgmt
....
#############################################################
# E-mail settings
#############################################################
$emailSmtpServer = "smtp.office365.com"
$emailSmtpServerPort = 587
$emailTo = $username
$emailSubject = "Here is your report"
$emailBodyHtml = "Please find <b>your report</b> attached here."
$emailUser = "account@example.com"
$emailPassword = "SuperStrongPassword"
$emailFrom = $emailUser
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential
$settings = @{ includeHiddenPages = $false; locale = "en-us" }
$powerBIReportConfiguration = @{ settings = $settings }
$export_body = @{ format = $format; powerBIReportConfiguration = $powerBIReportConfiguration }
#'{
#  format: "$format",
#  powerBIReportConfiguration: { settings: { includeHiddenPages: false, locale: "en-us" } }
#}'
.....

2. PowerAutomate

Export and email a Power BI report with Power Automate

Schedule, Export and Email Power BI Reports using Power Automate

yingyinr_0-1647248497961.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.