Forum Discussion
Can't refresh dynamic API URL in Power BI service
- 1 year ago
Hello jimbob2285,
Thanks for getting back and for providing those additional details.You're absolutely on the right track using RelativePath with Web.Contents is the correct solution to make your API call refreshable in the Power BI Service. You're very close, and the issue now seems to be related to how the parameters and authentication are being passed in the M code.
Key things to check:
- Keep your BaseUrl simple and static. It should not include parameters or dynamic segments.
- Use RelativePath only for the fixed portion of the endpoint path like /v1/organizations.
- Pass start, limit, and api_token using the Query option as a record. This is critical Power BI expects query parameters to be passed in this structured format to allow refresh in the Service.
- Avoid string concatenation inside RelativePath or Query. These should be clearly separated.
- If your API uses an API key in the query string, include it in the Query record as well. If it uses headers, you’ll need to configure it using the Headers option inside Web.Contents.
Here are two official docs that explain this pattern clearly:
- Web.Contents with RelativePath & Query: https://learn.microsoft.com/en-us/powerquery-m/web-contents
- Why dynamic URLs are blocked: https://learn.microsoft.com/en-us/power-bi/connect-data/refresh-data#refresh-and-dynamic-data-sources
- 1 year ago
Hello jimbob2285,
Thanks for sharing more details, you're really close. The issue now is with how the Query parameter is being passed.Power BI expects Query to be in a structured format using key-value pairs, not as a single concatenated string like "api_token=XXXX". This is a common roadblock. Instead of building one string, you should treat each query parameter as a separate item in a list (or "record") so Power BI can safely handle them and construct the URL properly for both Desktop and Service refresh.
Hello jimbob2285,
Thanks for the update and You've correctly implemented the RelativePath and Query structure, which is why it's now recognized as a valid static path and refreshes fine in Desktop. The issue you're seeing now in power bi service please consider raising a Microsoft support ticket for further investigation. You can explain all the steps you have taken to help them better understand the issue.
You can create a Microsoft support ticket with the help of the link below:
https://learn.microsoft.com/en-us/power-bi/support/create-support-ticket
Best Regards,
Ganesh singamshetty.
Hi v-ssriganesh
Thanks for clarifying that I've got the RelativePath and Query code structured correctly
I think I've sorted the credentials issue in the service
- The solution I've found, which @florianh suggested in this thread: Failed to update data source credentials
- Was to tick "Skip Test Connection" when editing the Data Source Credentials
- I'm guessing that because of the way the URL is constructed in the M code, to bring back and combine all the paginated pages
- That the Power BI Service only supplies the base URL when testing the connection
- Which will obviously fail, as it doesn't contain the API Key
- So, I presume skipping the test connection lest you set up the credentials
- Which then work correctly when refreshing the data set, as the full url, with the API Key, is passed to the API
Can you confirm that this is the accepted solution?
Thanks for all your help with this, I simply wouldn't have got there without you
Cheers
Jim