<?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: Power BI API empty JSON result set in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1497473#M26484</link>
    <description>&lt;P&gt;There are a couple of API calls that behave like this. Read up on Value.MetaData and manual exception handling.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the "it does not make sense"&amp;nbsp; part. You are absolutely right.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2020 00:09:08 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2020-11-17T00:09:08Z</dc:date>
    <item>
      <title>Power BI API empty JSON result set</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1493923#M26463</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result of my API call returns empty JSON sets means I receive the expected amount of sets (rows) but none contains data.&lt;/P&gt;&lt;P&gt;This issue only appears for the ActivityEvent cmdlet when I issue the following commands/script (sorry, indenting does not work here):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;## ########################################################################
## Power BI Logon
## ########################################################################

$CredentialUser = "MASKED"
$CredentialPassword = ConvertTo-SecureString "MASKED" -asplaintext -force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $CredentialUser, $CredentialPassword

## Connect-PowerBIServiceAccount
Connect-PowerBIServiceAccount -Credential $Credential

## ########################################################################
## Set Constants
## ########################################################################

$SqlServer = "MASKED"
$SqlDatabase = "MASKED"

$Days = 1 ## Last X days for delta load
$DaysOffset = -1
$DateNow = Get-Date

## ########################################################################
## Empty SQL Server Staging Area Table
## ########################################################################

Invoke-Sqlcmd -ServerInstance $SqlServer -Database $SqlDatabase -Query "TRUNCATE TABLE [SA].[tb_powerbi_service_event_all]"

## ########################################################################
## Load Activity Events
## ########################################################################

$Date = $DateNow.Date.AddDays($DaysOffset)

For($i = 1; $i -le $Days; $i++)
{
$ActivityEvents = Get-PowerBIActivityEvent -StartDateTime $Date.ToString("yyyy-MM-ddT00:00:00.000") -EndDateTime $Date.ToString("yyyy-MM-ddT23:59:59.999") | ConvertFrom-Json
if ($ActivityEvents.Count -gt 0) 
{
$ActivityEvents | foreach {
$SqlQuery = `
"
SET QUOTED_IDENTIFIER OFF

INSERT INTO [SA].[tb_powerbi_service_event_all] 
(
[event_id]
, [event_name]
, [activity_id]
, [activity_name]
, [user_key]
, [user_id]
, [workspace_id]
, [workspace_name]
, [capacity_id]
, [capacity_name]
, [tenant_id]
, [flag_success]
, [created_datetime]
, [request_id]

, [load_datetime]

)
VALUES 
(
""" + $_.Id + """
, """ + $_.Operation + """
, """ + $_.ActivityId + """
, """ + $_.Activity + """
, """ + $_.UserKey + """
, """ + $_.UserId + """
, """ + $_.WorkspaceId + """
, """ + $_.WorkspaceName + """
, """ + $_.CapacityId + """
, """ + $_.CapacityName + """
, """ + $_.OrganizationId + """
, """ + $_.IsSuccess + """
, """ + $_.CreationTime + """
, """ + $_.RequestId + """

, GETDATE()
)

SET QUOTED_IDENTIFIER ON
"
Invoke-Sqlcmd -ServerInstance $SqlServer -Database $SqlDatabase -Query $SqlQuery -ErrorAction SilentlyContinue
}
}
$Date = $Date.AddDays(-1)
}

## ########################################################################
## Logoff from Power BI
## ########################################################################

Disconnect-PowerBIServiceAccount&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For others like Capacity, Workspace or specifically filtered ActivityEvents like ViewReport it works fine.&lt;/P&gt;&lt;P&gt;The account I use is Power BI Service Admin and of type windows service account in AD and AAD.&lt;/P&gt;&lt;P&gt;With my personal account it also works fine when I execute the script.&lt;/P&gt;&lt;P&gt;All my scripts are executed with Windows Task Scheduler while all scripts execute fine and use all the same structure only the above script returns empty result sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's also interesting when I execute the above script manually in PowerShell (not via Run Job in Task Scheduler) I receive data as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone has an idea how to move on with troubleshooting this?&lt;/P&gt;&lt;P&gt;For me it does not make sense that all other scripts using the same settings/template just using different CMDlets (they also need Power BI Service Admin account) work but only this one not and the manual execution works as well. Mmmh.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;SteWi&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 10:09:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1493923#M26463</guid>
      <dc:creator>SteWi</dc:creator>
      <dc:date>2020-11-14T10:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API empty JSON result set</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1497473#M26484</link>
      <description>&lt;P&gt;There are a couple of API calls that behave like this. Read up on Value.MetaData and manual exception handling.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the "it does not make sense"&amp;nbsp; part. You are absolutely right.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 00:09:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1497473#M26484</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-11-17T00:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API empty JSON result set</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1498219#M26487</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;thanks for your answer. Do you have a code snippet based on my script what you mean with Value.MetaData or a helping link?&lt;/P&gt;&lt;P&gt;Something like this&amp;nbsp;$ActivityEvents[1].Id.Metadata does not work. There is no MetaData function I could find during my search.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 07:45:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1498219#M26487</guid>
      <dc:creator>SteWi</dc:creator>
      <dc:date>2020-11-17T07:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API empty JSON result set</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1498322#M26488</link>
      <description>&lt;P&gt;Oh my, I got it. This is the only script where I did not remove the following at the start of the script (and I did not paste it into my post). It turns out when the script contains import-module command the json sets are empty.&lt;/P&gt;&lt;P&gt;Import-Module MicrosoftPowerBIMgmt&lt;BR /&gt;Import-Module SqlServer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After removing the 2 lines it works now.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 08:18:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-empty-JSON-result-set/m-p/1498322#M26488</guid>
      <dc:creator>SteWi</dc:creator>
      <dc:date>2020-11-17T08:18:59Z</dc:date>
    </item>
  </channel>
</rss>

