The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello,
I'm trying to get the data from an API with:
Json.Document(Web.Contents("https://dominio.com/api/index.php/v1/GetData", [Headers=[Authorization="Bearer xxxx", Accept="*/*"]]))
The data format is JSON, and the authentication is via token.
However, this is retrieving an empty table.
Testing the API with Postman, I'm able to obtain the data I need.
Thanks!
Hi @webportal ,
One possible cause is that the API requires a specific content type header to return the JSON data. You can check the documentation of the API or use Postman to see what content type header is expected by the API. For example, some APIs may require Content-Type: application/json
or Content-Type: text/plain
. You can then add this header to your Web.Contents function, like this:
Json.Document(Web.Contents(“https://dominio.com/api/index.php/v1/GetData”, [Headers=[Authorization=“Bearer xxxx”, Accept=“/”, Content-Type=“application/json”]]))
Another possible cause is that the API returns a nested JSON object that Power BI cannot automatically flatten into a table. You can check the structure of the JSON data by using Postman or by loading the data as a list in Power BI. For example, if the JSON data looks like this:
{ “data”: [ { “id”: 1, “name”: “Alice” }, { “id”: 2, “name”: “Bob” } ] }
You can then use the Record.Field function to access the data field, like this:
Json.Document(Web.Contents(“https://dominio.com/api/index.php/v1/GetData”, [Headers=[Authorization=“Bearer xxxx”, Accept=“/”]]))[data]
This will return a list of records that you can then convert into a table.
A third possible cause is that the API has some limitations or restrictions on the number of requests, the size of the response, or the time interval between requests. You can check the documentation of the API or use Postman to see if there are any errors or warnings returned by the API. For example, some APIs may have a rate limit that prevents you from making too many requests in a short period of time. You can then adjust your query parameters or use a pagination function to avoid exceeding the limit.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks, I've tried:
= Json.Document(Web.Contents("https://www.dominio.com/api/GetData", [Headers=[Authorization="Bearer xxx", Accept="*/*", Content-Type="application/json"]]))
Which returns the error:
Expression.SyntaxErrror
Hi @webportal ,
Could you please provide the complete error message?
Best regards,
Community Support Team_yanjiang
Thanks, I tried this and it worked:
= Json.Document(Web.Contents("https://www.dominio.com/api/GetData", [Headers=[Authorization="Bearer xxx", Accept="*/*", Content="application/json"]]))
But now I have another situation.
Of the 3 tables I have in Joomla, which I'm fetching via API, one of them worked (according to the image above) and another 2 with different errors:
1) One of them says that the format is invalid
2) And the other one says it gives me error 404:
Any tips on how to resolve this?
The data source is a REST API that provides the data in JSON format.
The authentication is trhough a Bearer token.
If more info is needed, pls let me know.
Thanks
@webportal Please Can you elaborate on which data source are using for data load in Power bi. Thank You!!
Thanks, I tried this and it worked:
= Json.Document(Web.Contents("https://www.dominio.com/api/GetData", [Headers=[Authorization="Bearer xxx", Accept="*/*", Content="application/json"]]))
But now I have another situation.
Of the 3 tables I have in Joomla, which I'm fetching via API, one of them worked (according to the image above) and another 2 with different errors:
1) One of them says that the format is invalid
2) And the other one says it gives me error 404:
Any tips on how to resolve this?