1

I keep getting this error in my power point after running the above code (to get an artist from Spotify API) :

curl --request GET \ --url https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy \ --header 'Authorization: Bearer XXX'

At line:2 char:5
+   --url 'https://api.spotify.com/v1/search?q=Lilbaby&type=artist' \
+     ~
Missing expression after unary operator '--'.
At line:2 char:5
+   --url 'https://api.spotify.com/v1/search?q=Lilbaby&type=artist' \
+     ~~~
Unexpected token 'url' in expression or statement.
At line:3 char:5
+   --header 'Authorization: Bearer BQCr8A...QoBCa4'
+     ~
Missing expression after unary operator '--'.
At line:3 char:5
+   --header 'Authorization: Bearer BQCr8A...QoBCa4'
+     ~~~~~~
Unexpected token 'header' in expression or statement.
+ CategoryInfo          : ParserError: (:) [], 
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator 

I have tried it multiple times but still the same result

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
The Dev
  • 11
  • 2
  • In *some* versions of Powershell,```curl``` is an alias for ```Invoke-WebRequest``` (see https://github.com/PowerShell/PowerShell/issues/5870) - try ```curl.exe``` instead to bypass the alias and invoke the executable, or just convert the call to using ```Invoke-WebRequest``` instead… – mclayton Jun 23 '23 at 13:33
  • The options with two dashes are not needed. See : https://curl.se/docs/httpscripting.html – jdweng Jun 23 '23 at 14:14

1 Answers1

0

In PowerShell

For albums

$headers = @{
    Authorization="Bearer ####### your access token ######"
    Content='application/json'
}

Invoke-RestMethod -Method Get -Uri "https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy" -Headers $headers

Result enter image description here

For artists

$response = Invoke-RestMethod -Method Get -Uri "https://api.spotify.com/v1/search?q=Lilbaby&type=artist" -Headers $headers
$releases | get-member 
$releases.artists

Result enter image description here

References

#1 curl in PowerShell

#2 Powershell Invoke-RestMethod Authorization Header

#3 Wrangling REST APIs with PowerShell JSON Examples

Bench Vue
  • 5,257
  • 2
  • 10
  • 14