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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Housden996
Helper II
Helper II

Xero Data refresh in Service

Hi all

 

I have managed to connect to my companies xero API via the custom connector, extract and automatically update the bearer token in Power BI Desktop using the following M Query:

 

let
authUrl = "https://identity.xero.com/connect/token",

formBody =
[
   grant_type = "client_credentials",
   client_id = "xxxxxxxxxxxx",
   client_secret = "xxxxxxxxxxx",
   scope = "accounting.transactions.read"   
], 

AuthResponse= Web.Contents(authUrl,
[Headers=[#"Content-Type" = "application/x-www-form-urlencoded"],Content = Text.ToBinary(Uri.BuildQueryString(formBody))]),

AuthJson = Json.Document(AuthResponse),
    #"Converted to Table" = Record.ToTable(AuthJson),
    token = #"Converted to Table"{0}[Value],

bearer = Text.Combine({"bearer", token}, " "),
    Source = Json.Document(Web.Contents("https://api.xero.com/api.xro/2.0/CreditNotes", [Headers=[#"xero-tenant-id"="xxxxxxxxxxx", Authorization=bearer, Accept="application/json", #"Content-Type"="application/json"]])),
    #"Converted to Table2" = Table.FromRecords({Source}),
    #"Expanded CreditNotes2" = Table.ExpandListColumn(#"Converted to Table2", "CreditNotes"),
    #"Expanded CreditNotes" = Table.ExpandRecordColumn(#"Expanded CreditNotes2", "CreditNotes", {"CreditNoteID", "CreditNoteNumber", "Payments", "ID", "HasErrors", "CurrencyRate", "Type", "Reference", "RemainingCredit", "Allocations", "HasAttachments", "Contact", "DateString", "Date", "Status", "LineAmountTypes", "LineItems", "SubTotal", "TotalTax", "Total", "UpdatedDateUTC", "CurrencyCode"}, {"CreditNoteID", "CreditNoteNumber", "Payments", "ID.1", "HasErrors", "CurrencyRate", "Type", "Reference", "RemainingCredit", "Allocations", "HasAttachments", "Contact", "DateString", "Date", "Status.1", "LineAmountTypes", "LineItems", "SubTotal", "TotalTax", "Total", "UpdatedDateUTC", "CurrencyCode"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded CreditNotes",{{"DateString", type datetime}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"DateString", type date}})
in
    #"Changed Type1"

 

So when I manualy refresh data in the desktop report this works.

 

I have published this to Power BI service and now I am getting a connection error when I try to connect the gateway with no real error code or message to help me resolve the issue. 

I have attempted anonymous organizational wich I am using in PBI Desktop as well as the the service principal in Power BI Service which doesnt work as well. I have this working for the MS Graph API as well as our service desk providers API just not this one.

 

Can any one notice any stand out issues which could be causing the gateway to fail/a fix?

 

Thanks in advance!

Alex 

1 REPLY 1
Thomaslleblanc
Super User
Super User

If you workspace can 'edit models', try to create the same in a new data model in service.

 

If not, see if you can create a dataflow in the service and use the same M code in the Advanced Editor in Power Query

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors