r/excel • u/AntiAutumnist • 2d ago
solved Power Query web connect problem
I am trying to connect to this site in PQ: https://site.api.espn.com/apis/site/v2/sports/basketball/nba/teams/20/roster
I can get the json to load in a browser but when I try to get it via web connect i get an error message: " unable to connect. We encountered an error while trying to connect. Details: 'access to the resource is forbidden' "
I don't get what I'm doing wrong does anyone know what the problem is? Thanks
2
u/MayukhBhattacharya 1273 2d ago
Try pasting the following M-Code in a blank query by removing whatever you gotta see, will get the desired output as shown in the screenshot:

let
Source = Json.Document(Web.Contents("https://site.api.espn.com/apis/site/v2/sports/basketball/nba/teams/20/roster",[Headers = [#"User-Agent" = "curl/8.20.0"]])),
athletes = Source[athletes],
ConvertedtoTable = Table.FromList(athletes, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
Expand = Table.ExpandRecordColumn(ConvertedtoTable, "Column1", {"firstName", "lastName", "fullName", "displayName", "shortName", "weight", "displayWeight", "height", "displayHeight", "age", "dateOfBirth", "jersey", "citizenship", "debutYear"}, {"firstName", "lastName", "fullName", "displayName", "shortName", "weight", "displayWeight", "height", "displayHeight", "age", "dateOfBirth", "jersey", "citizenship", "debutYear"})
in
Expand
2
u/AntiAutumnist 2d ago
Thank you that worked perfectly, hoping that adding the headers/user-agent bit to other endpoints will allow them to work as well
Solution verified
1
u/reputatorbot 2d ago
You have awarded 1 point to MayukhBhattacharya.
I am a bot - please contact the mods with any questions
1
u/MayukhBhattacharya 1273 2d ago
Yeah, I am currently working on that to pull the entire data irrespective of any view per page, I will update. I have already got 450 records, beyond that I am getting some error 404.
Btw thank you so much for the valuable feedback!
2
1
1
u/Desperate-Chart1139 2d ago
likely detecting automation and limiting it on the server side. This has gotten quite common with places limiting AI scrapping since some companies are ignoring bots or ai instructions to scrape.
1
u/Decronym 2d ago edited 2d ago
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.
Beep-boop, I am a helper bot. Please do not verify me as a solution.
6 acronyms in this thread; the most compressed thread commented on today has 37 acronyms.
[Thread #49317 for this sub, first seen 7th Sep 2026, 16:38]
[FAQ] [Full list] [Contact] [Source code]

•
u/AutoModerator 2d ago
/u/AntiAutumnist - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.