Forum Discussion
Data source accessing a web URL which requires Authentication headers
- Anonymous8 years ago
Thank you. I have now managed to spend some more time on this.
I can confirm that the suggested work-around to use the RelativePath parameter solves the problem.
I do not need to use static values for my Authorization parameters, which is good, because I don't want to have to duplicate these across many queries. This is the query which now works for me.
Source = Json.Document(Web.Contents("https://api.harvestapp.com/", [ RelativePath="v2/time_entries", Query=[from=DateThreshold], Headers=[Authorization="Bearer " & HarvestAccessToken, #"Harvest-Account-ID"=HarvestAccountId, #"User-Agent"="PowerBI_DBRetrieval (" & HarvestUserEmail & ")"]] )),The important point, for this API, is that the root URL is not authenticated, so this passes the credentials check. When the real query is executed, the RelativePath, Query, and Headers are all correctly processed.
Thank you.
I have now tried this with a parameterised query, but I get the same problem with the credentials. The credentials check uses the 'bare' URL, and doesn't pass the authentication headers, so the credentials check fails.
This is the URL I'm using now:
Source = Json.Document(Web.Contents("https://api.harvestapp.com/v2/time_entries",
[
Query=[from=DateThreshold],
Headers=[Authorization="Bearer " & HarvestAccessToken, #"Harvest-Account-ID"=HarvestAccountId, #"User-Agent"="PowerBI_DBRetrieval (" & HarvestUserEmail & ")"]]
)),but when I try to refresh I get:
Your data source can't be refreshed because the credentials are invalid. Please update your credentials and try again.
And, then the credentials gives this error:
Failed to update data source credentials: Web.Contents failed to get contents from 'https://api.harvestapp.com/v2/time_entries' (404): Not FoundHide details
Activity ID: 89558fd1-d30d-304f-c391-e67484bb4002
Request ID: bf3b4ee0-9890-55f1-5389-37b07ff45fef
Status code: 400
Time: Fri Jan 12 2018 10:17:20 GMT+0000 (GMT Standard Time)
Version: 13.0.3671.248
Cluster URI: https://wabi-uk-south-redirect.analysis.windows.net
Anonymous,
Provide static values for these parameters(Authorization, User-Agent,etc) in your Headers, and combine RelativePath and Query option in your code. For more details, please review abedkhooli's reply in the following similar thread.
https://community.powerbi.com/t5/Service/Refreshing-a-Restful-Data-Source-with-API-Key/td-p/131298
Regards,
Lydia
- Anonymous8 years agoNot applicable
Thank you. I have now managed to spend some more time on this.
I can confirm that the suggested work-around to use the RelativePath parameter solves the problem.
I do not need to use static values for my Authorization parameters, which is good, because I don't want to have to duplicate these across many queries. This is the query which now works for me.
Source = Json.Document(Web.Contents("https://api.harvestapp.com/", [ RelativePath="v2/time_entries", Query=[from=DateThreshold], Headers=[Authorization="Bearer " & HarvestAccessToken, #"Harvest-Account-ID"=HarvestAccountId, #"User-Agent"="PowerBI_DBRetrieval (" & HarvestUserEmail & ")"]] )),The important point, for this API, is that the root URL is not authenticated, so this passes the credentials check. When the real query is executed, the RelativePath, Query, and Headers are all correctly processed.