r/PowerShell • u/semicolonsemicolon • May 29 '26
Solved Invoke-WebRequest to call the reddit api suddenly broken
Been running a script forever without issue. You don't need OAuth2 to grab the last 100 comments of a user like this:
https://api.reddit.com/user/spez.json?limit=100&after=or
https://www.reddit.com/user/spez.json?limit=100&after=A few months ago I added the -UseBasicParsing tag.
Today I'm getting
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommandMy line of code is $response = Invoke-WebRequest -UseBasicParsing $url | ConvertFrom-Json where $url looks like the https lines above.
Can anyone shed light, please? Thanks.
25
Upvotes
View all comments
Show parent comment
13
u/semicolonsemicolon May 29 '26
Goddammit. You're absolutely right. It's no coincidence that my script started bombing yesterday. I'm not running a bot, I'm just trying to moderate a subreddit.
To solve this problem I sent a -Header with my WebRequest that contains my access token. Instead of GET requests to api.reddit.com those requests have to be to oauth.reddit.com.
I will update the flair to Solved. Thank you to all who offered some advice. Although u/teethingrooster sent me down quite the rabbit hole to nowhere. Ha!