I want to get data from AppAnnie via their API through Powershell.
Authentication is described here: http://support.appannie.com/entries/23215057-2-Authentication
My code looks like:
$apiKey = "someApiKey" $url = "api.appannie.com/v1.1/apps/ios/app/661947195/ranks?start_date=2014-04-23&end_date=2012-04-23&interval=hourly&countries=US+CN" $headers = @{"Authorization" = "Bearer " + $apiKey} $appAnnieResult = Invoke-RestMethod -Uri $url -Headers $headers $appAnnieResult The result:
Invoke-RestMethod : Der Remoteserver hat einen Fehler zurückgegeben: (401) Nicht autorisiert. What am I missing?
Tried with and without http://, https:// in front of URL
To try it out you'll need an APIKey from AppAnnie (for which you'll need a free account)
Thank you!
Sandro
Update: with the suggest https prefix and extensive logging I get this as header information
Transfer-Encoding=chunked Connection=keep-alive Keep-Alive=timeout=10 Vary=Accept-Language,Cookie Content-Language=en Content-Type=application/json Date=Thu, 24 Apr 2014 16:03:06 GMT Set-Cookie=sessionId="someLongSessionId"; Path=/ Server=nginx sessionId="theSameLongSessionId"= The response type now is
"StatusCode": 400, "StatusDescription": "BAD REQUEST" And I thought "Bad request" would be worse than "Unauthorized". But it looks like authorization is no longer the issue (there seems to be a session), but then something with my request must be wrong, right? From the given example I only changed the appId and the dates (checked the date for correct position of day and month)
Update 2: Attempts with different parameters, responses as a comment at the end of the lines
$url = "https://api.appannie.com/v1.1/apps/ios/app/848160327/ranks?start_date=2014-04-23&end_date=2012-04-24" #400, bad request $url = "https://api.appannie.com/v1.1/apps/ios/app/848160327/ranks?countries=US+CN" #403, forbidden $url = "https://api.appannie.com/v1.1/apps/ios/app/848160327/ranks?interval=hourly" #403, forbidden $url = "https://api.appannie.com/v1.1/apps/ios/app/848160327/ranks?countries=US+CN&interval=hourly" #403, forbidden $url = "https://api.appannie.com/v1.1/apps/ios/app/848160327/ranks?start_date=2014-04-23&end_date=2012-04-24&interval=hourly" #400, bad request $url = "https://api.appannie.com/v1.1/apps/ios/app/848160327/ranks?start_date=2014-04-23&end_date=2012-04-24&countries=US+CN" #400, bad request I think the responses are what is to be expected from the docs, as start_date and end_date are the only required parameters. As long as they are in, it's a bad request (400), if not it becomes a forbidden (403)