Forum Discussion
Power Query API Authentication
- 3 years ago
Hi Anonymous
Yeah, we had the wrong Content-Type - give below a try:
let url = "https://www.space-track.org/ajaxauth/login", identity = "change_this", password = "also_change_this", query = "https://www.space-track.org/basicspacedata/query/class/boxscore", headers = [#"Content-Type" = "application/x-www-form-urlencoded"], // this was the problem response = Web.Contents(url, [ Headers = headers, Content = Text.ToBinary( "identity=" & identity & "&password=" & password & "&query=" & query ) ]), jsonResponse = Json.Document(response) in jsonResponseI actually tested it 😊
Please mark this as ANSWER if it helped.
P.S.: I saw there are some rate limiting guardrails in place on their side -> don't press the refresh button too often
Hi Anonymous ,
Please paste in PowerQuery exactly the code i've sent AFTER replacing identity and password (and maybe query) AND choose anonymous when prompted for credentials.
I think you're trying to use some API key stored in credentials manager - that does not work.
Please mark the relevant replies as answer if they helped.
- ams13 years agoResponsive Resident
Hi Anonymous
Yeah, we had the wrong Content-Type - give below a try:
let url = "https://www.space-track.org/ajaxauth/login", identity = "change_this", password = "also_change_this", query = "https://www.space-track.org/basicspacedata/query/class/boxscore", headers = [#"Content-Type" = "application/x-www-form-urlencoded"], // this was the problem response = Web.Contents(url, [ Headers = headers, Content = Text.ToBinary( "identity=" & identity & "&password=" & password & "&query=" & query ) ]), jsonResponse = Json.Document(response) in jsonResponseI actually tested it 😊
Please mark this as ANSWER if it helped.
P.S.: I saw there are some rate limiting guardrails in place on their side -> don't press the refresh button too often
- Anonymous3 years agoNot applicable
You're Amazing, thanks ams1!!
- cri71 year agoNew Member
Hello,
the solution proposed worked beautifully until recently. Now login and query must be in two separate steps (spacetrack requirement). I am using the code below but I am not able to login properly (I am using the code below). Is anyone able to help?
Thanks
// Step 1: Perform login to Space-Track (POST request)
loginResponse = Web.Contents(urlLogin, [
Headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
Content = Text.ToBinary(requestBody)
]),
// Step 2: Extract response headers
responseHeaders = Value.Metadata(loginResponse)[Headers],
// Step 3: Check if the 'Set-Cookie' header is present
cookies = if List.Contains(Record.FieldNames(responseHeaders), "Set-Cookie") then
Record.Field(responseHeaders, "Set-Cookie")
else
error "Login failed: Unable to authenticate with Space-Track, no cookies found.",