Forum Discussion
Live Agent (LA) - API connection to Power BI
Hello,
I established API connection to my power BI report. API is from Live Agent (over URL and Api Key) And it work perfect for several queries. BUt now I have another query: Ticket History with following URL:
https://geodishyster.ladesk.com/api/v3/tickets/5c81sm9l/history
And I need this part of URL: 5c81sm9l to be replace dynamically with Values from My other Query: Query Name: ID's (Ticket ID), Column from that query: ID. SO i can pull all the tickets existing in that list, SO i need some kind of for each / for loop.
How to achieve this ?
Thank you.
5 Replies
- LK0913Regular Visitor
Hello ShivekMahara,
Thank you very much for your detailed calrification. I can say this is working, but from some reason it is super slow, and data cannot be filtered / sorted into my ID's (Ticket ID) query, also data canot be loaded into power BI from some reason, it is taking to long and stuck at the end . Do you know what could be the reason ?- ShivekMaharajImpactful Individual
Hi LK0913,
Yes, that can happen with this pattern.
The custom function approach works, but there is an important performance tradeoff: Power Query is effectively making one API request for every Ticket ID in your ID's table.
So if you have 500 Ticket IDs, that can mean roughly 500 separate calls to:
/api/v3/tickets/{id}/historyand potentially more during preview/refresh because Power Query can evaluate referenced queries multiple times.
That would explain why it works functionally but becomes very slow when loading the full dataset.
A few things I would try:
- Filter the ID's query as early as possible before invoking fnTicketHistory.
If you only need a subset of tickets, reduce that list first and only then call the API. - Make sure the staging ID's query itself is not being loaded into the model if you only use it as an intermediate query. You can right-click it and disable Enable load.
- Test with perhaps 10 or 20 Ticket IDs first. If that loads quickly but 500+ becomes extremely slow, that confirms the bottleneck is the number of API calls rather than the transformation logic.
- Use Query Diagnostics in Power Query to see how many Web.Contents requests are actually being generated. Microsoft documents Query Diagnostics specifically for investigating slowdowns and background activity during query evaluation.
I would also avoid adding Table.Buffer() immediately. Microsoft notes that buffering can sometimes make queries slower rather than faster, so I would first prove that repeated evaluation is actually the issue before introducing it.
For the sorting/filtering part, I would do that on the ID's table before the custom function is invoked, for example:
FilteredIDs = Table.SelectRows( #"Previous Step", each [ID] <> null ), SortedIDs = Table.Sort( FilteredIDs, {{"ID", Order.Ascending}} ), WithHistory = Table.AddColumn( SortedIDs, "TicketHistory", each fnTicketHistory(Text.From([ID])) )That way Power Query only calls LiveAgent after you have already reduced and ordered the input list.
If you ultimately need the history for a very large number of tickets on every refresh, I would probably reconsider the architecture rather than calling the per-ticket endpoint hundreds or thousands of times from Power Query. For example, I would check whether LiveAgent exposes a bulk/history endpoint or another API route that lets you retrieve more records per request and then join them back to Ticket ID in Power Query.
LiveAgent’s API documentation does expose pagination and API limits, so reducing the number of round trips will usually matter much more than tweaking the DAX/model side.
- Filter the ID's query as early as possible before invoking fnTicketHistory.
- v-achippaCommunity Support
Hi LK0913,
Thank you for reaching out to Microsoft Fabric Community.
Thank you ShivekMaharaj for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa - ShivekMaharajImpactful Individual
Hi LK0913,
Yes, I would handle this with a small Power Query function and invoke it for each Ticket ID.
I would also keep the API host static and pass the changing part through RelativePath, rather than constructing a completely different URL for every row. That tends to behave better when the report is published to the Power BI Service.
For example:
(ticketId as text) => let Source = Json.Document( Web.Contents( "https://geodishyster.ladesk.com", [ RelativePath = "api/v3/tickets/" & ticketId & "/history", Headers = [ apikey = "YOUR_API_KEY" ] ] ) ) in SourceSave that as something like fnTicketHistory.
Then go back to your existing ID's query and add a custom column:
= Table.AddColumn( #"Previous Step", "TicketHistory", each fnTicketHistory(Text.From([ID])) )You can then expand the TicketHistory column to bring the history records into the table.
Microsoft documents both the use of RelativePath with Web.Contents and the pattern for invoking a custom function for each row.
I would prefer this over concatenating the full URL directly because Microsoft notes that dynamic data sources can cause refresh problems after publishing, while Web.Contents with a fixed base URL and dynamic RelativePath is one of the supported patterns for Service refresh.
One other thing I would check before running this against every ticket is whether the LiveAgent history endpoint has pagination or request-rate limits. If you have hundreds or thousands of ticket IDs, this approach means at least one API request per ticket, so refresh time can grow fairly quickly.