Forum Discussion
Retrieve API response headers
- 8 years ago
Hi,
I understand that they are methods to obtain the request headers, not response headers.
In this article:
explains this:
"[...] but even with those articles and videos at hand + the full documentation of the Web.Contents function here, you might not get some queries to work because of how Power Query’s refresh operation was designed to work on the Power BI Service and how some other features are limited like not being able to see the response header of your Web.Contents request when using the Value.Metadata function"
So, the conclusion I get is that the only way to get all the information from the responseheaders is to create a Custom Connector.
"[...] Request Limit, Throttling, Token expiration and response Headers– a big restriction with Power Query is that, by design, you are unable to see the headers of the response of your requests. You only get the body of the response, but the Header contains important information, like the next page url, total elements in the endpoint and more. Now with the Extensibility Model you are able to see exactly what the response Header provides and use the values to paginate or just create a query plan for your connector so you never get throttled."
Thank you all.
I'm looking to do the same thing. I'm calling a REST API through Web.Contents and would like to parse the response headers. In Postman, I've identified response headers I'd like to expose:
Back in Power Query, Value.Metadata on the response exposes the value for the "Content-Type" header, but nothing else.
Web searches yield varying answers from "you can't do that" to "use Python to read your IE cookies, start a local web server, and use Power Query to fetch values from the local server".
I feel there should be a M function that should be able to expose all response headers. Am I wrong?
Try WebMethod.head() or Odata.Feed(), If still can't retrieve the header of http request, I recommend you to use R script to get the http headers instead.
https://msdn.microsoft.com/en-us/query-bi/m/webmethod-head.
https://msdn.microsoft.com/en-us/query-bi/m/odata-feed.
Regards,
Jimmy Tao
- lauritxi8 years agoFrequent Visitor
Hi,
I understand that they are methods to obtain the request headers, not response headers.
In this article:
explains this:
"[...] but even with those articles and videos at hand + the full documentation of the Web.Contents function here, you might not get some queries to work because of how Power Query’s refresh operation was designed to work on the Power BI Service and how some other features are limited like not being able to see the response header of your Web.Contents request when using the Value.Metadata function"
So, the conclusion I get is that the only way to get all the information from the responseheaders is to create a Custom Connector.
"[...] Request Limit, Throttling, Token expiration and response Headers– a big restriction with Power Query is that, by design, you are unable to see the headers of the response of your requests. You only get the body of the response, but the Header contains important information, like the next page url, total elements in the endpoint and more. Now with the Extensibility Model you are able to see exactly what the response Header provides and use the values to paginate or just create a query plan for your connector so you never get throttled."
Thank you all.
- Anonymous7 years agoNot applicable
Hi,
So there exists a workaround to get the response header?
Can you give a bit more precise information, please?
regards,
Axel Vulsteke
- gabrielsroka7 years agoFrequent Visitor
Hi Anonymous,
You have to write a custom Data Connector. See https://github.com/Microsoft/DataConnectors
- tonmcg7 years agoResolver II
To round out this thread, I've confirmed the only way to retreive the response header for a Socrata API endpoint in Power BI is to build a custom connector.
Here's a screenshot of a custom connector I built to the City of Seattle Fire Emergency Calls endpoint. I use the Value.Metadata Power Query M function ask for the response headers:
Here's what the results look like after I test this query in Visual Studio:
Note: I'm not using the OData endpoint but rather, the regular endpoint for this Http request to the Socrata API.