# PowerBI - connection to the Auth0 user list and log

**URL:** <https://community.auth0.com/t/powerbi-connection-to-the-auth0-user-list-and-log/42524>\
**Category:** Get Help\
**Created:** [May 6, 2020, 10:12pm UTC](https://community.auth0.com/t/powerbi-connection-to-the-auth0-user-list-and-log/42524 "2020-05-06T22:12:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfaloon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kfaloon/32/13074_2.png) [@kfaloon](https://community.auth0.com/u/kfaloon)\
**Post date:** [May 6, 2020, 10:12pm UTC](https://community.auth0.com/t/powerbi-connection-to-the-auth0-user-list-and-log/42524/1 "2020-05-06T22:12:37Z")

</div>

Has anyone had success connecting there Auth0 user database and log file into powerBI?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [May 7, 2020, 12:50pm UTC](https://community.auth0.com/t/powerbi-connection-to-the-auth0-user-list-and-log/42524/2 "2020-05-07T12:50:33Z")

</div>

Hey there @kfaloon!

Researched our community forum a little bit and found this. Think this might be helpful!

> [@Can Auth0 integrate PowerBI?](http://community.auth0.com/t/can-auth0-integrate-powerbi/28100/5):
>
> There may be two options for this integration: Option 1 : Provisioning the users on Azure AD with Auth0 identities This option is explained for Office 365 app but the same idea may apply for PowerBI too. In this option, the domain federation is done in Azure AD so it should work for every application that uses Azure AD to authenticate technically. On the first link below, there is a sample rule to create any required licenses on the Azure AD side, so that after a user logs in using a 3rd part…

---

<div class="post-metadata">

**Author:** ![mpekar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mpekar/32/20872_2.png) [@mpekar](https://community.auth0.com/u/mpekar)\
**Post date:** [September 10, 2021, 4:46pm UTC](https://community.auth0.com/t/powerbi-connection-to-the-auth0-user-list-and-log/42524/3 "2021-09-10T16:46:50Z")

</div>

I read this question a bit differently than konrad did. I wanted to extract users from Auth0 to Power BI for reporting purposes. Not sure if this is the route we’ll go but it’s one way.

```auto

let
  FetchBearerTokenResult = Json.Document(Web.Contents("https://YOURCOMPANY.auth0.com/oauth/token", [
    IsRetry=true,
    Content=Json.FromValue([client_id=YOUR_CLIENT_ID,
      client_secret=YOUR_CLIENT_SECRET
      audience="https://YOURCOMPANY.auth0.com/api/v2/", 
      grant_type="client_credentials"]), 
    Headers=[#"Content-Type"="application/json"]
  ])),
  BearerToken=FetchBearerTokenResult[access_token],
  StartJobResult = Json.Document(Web.Contents(
    "https://deltaplastics.auth0.com/api/v2/jobs/users-exports", 
    [
      IsRetry=true,
      Content=Json.FromValue([format="csv"]), 
      Headers=[
        #"Accept"="application/json", 
        #"Content-Type"="application/json",
        #"Authorization"="Bearer " & FetchBearerTokenResult[access_token]
      ]
    ]
  )),
  JobResultId = StartJobResult[id],
  FinishJobResults = List.Generate(
    () => [delayInSeconds=1, attempts=0, done=false, location=null, status="First Run", percentage_done=0, created_at=null, connection_id=null],
    each ([done] = false) and ([attempts] < 24),
    (_) => 
      if (_[location] <> null) then 
        [delayInSeconds=-1, attempts=-1, done=true, location=_[location], status="Done", percentage_done=100, created_at=null, connection_id=null]
      else Function.InvokeAfter(() =>
        let 
          testResult = Json.Document(Web.Contents(
          "https://YOURCOMPANY.auth0.com/api/v2/jobs/" & StartJobResult[id], 
          [
            IsRetry=true,
            Headers=[
                #"Accept"="application/json",
                #"Authorization"="Bearer " & FetchBearerTokenResult[access_token]
            ] 
          ]
          )),
          DT4=Diagnostics.Trace(TraceLevel.Information, "Job Status: " & testResult[status] 
            & ", Time Left: " & testResult[time_left_seconds], "Erp"),
          resultDone = Record.HasFields(testResult, "location"),
          resultLocation = if resultDone then testResult[location] else null,
          delay = if Record.HasFields(testResult, "time_left_seconds") 
            then testResult[time_left_seconds]
            else _[delayInSeconds] + 3
      in
          [
              delayInSeconds=delay, attempts=_[attempts] + 1, 
              done=false,
              location=resultLocation, status=testResult[status],
              percentage_done=testResult[percentage_done],
              created_at=testResult[created_at], connection_id=testResult[connection_id]
          ]
      , #duration(0, 0, 0, _[delayInSeconds]))
  ),
  FinishJobResultsTable = Table.FromList(FinishJobResults, Record.FieldValues),
  ZipUri = List.Last(FinishJobResults)[location],
  Zip = Web.Contents(ZipUri),
  UsersText = Binary.Decompress(Zip, Compression.GZip) 
in
  Table.PromoteHeaders(Csv.Document(UsersText))

```
