goodmanjl531 Posted August 29, 2024 Posted August 29, 2024 (edited) I have search around in the forums, but not being very well versed in API calls makes it difficult to figure out what im really looking for so any help will be greatly appreciated. I need to make a call to the API URL and get the reply back and drop it into a text file. if i put the url in a webbrowser with the key i can get a respsonse, but not sure how to get this into a text file web response looks like this I only want the data... I have a URL and an authorization key but not having any luck... expandcollapse popupget_authentication_test() Func get_authentication_test() Local $oHttp = Null, _ $oComErr = Null Local $iHttpStatus = 0 Local $sResponse = "", _ $sPostData = "" ConsoleWrite(@CRLF & "Executing API" & @CRLF) ;Set COM error handler $oComErr = ObjEvent("AutoIT.Error", "com_error_handler") ;Create a HTTP COM object $oHttp = ObjCreate("winhttp.winhttprequest.5.1") If @error Then ConsoleWrite("Unable to create http request object." & @CRLF) Exit -1 EndIf ConsoleWrite("WinHttpRequest object created." & @CRLF) With $oHttp ;Open GET request .Open("GET", "https://.flowgear.net/CLIST4", False) ;Set request headers and options .SetRequestHeader("Content-Type", "application/json") ;Send request ;.Send('{"username":"admin","password":"123","clientId":"AUTOIT_TEST","clientSecret":"E5AE290AB76A4B1E"}') original .Send('{"clientSecret":"AUTHKEYHERE"}') If @error Then ConsoleWrite(StringFormat("SEND ERROR: (0x%X) %s", $oComErr.Number, $oComErr.Description) & @CRLF) Return EndIf ;Get status code and response $iHttpStatus = .Status $sResponse = .ResponseText ;If status code isn't okay If $iHttpStatus <> 200 Then ConsoleWrite("HTTP Status : " & String($iHttpStatus) & @CRLF) ConsoleWrite("HTTP Response: " & @CRLF & $sResponse & @CRLF) Return EndIf EndWith ConsoleWrite("API Response:" & @CRLF & $sResponse & @CRLF) EndFunc Func com_error_handler($oError) #forceref $oError Return EndFunc got above code from .. Edited August 29, 2024 by goodmanjl531 update question
Andreik Posted August 29, 2024 Posted August 29, 2024 What do you get in the console after you run the script? Do you have any response from the server? 22 minutes ago, goodmanjl531 said: .Open("GET", "https://.flowgear.net/CLIST4", False) Also this link doesn't look right starting with a dot. Please be sure you use the proper API link.
Solution goodmanjl531 Posted August 29, 2024 Author Solution Posted August 29, 2024 i was able to get it figured out.. #include <Inet.au3> #include <json.au3> $url = "https://.flowgear.net/CLIST1?auth-key=<AUTHKEYHERE>" $data = _INetGetSource($url) $json = _JSON_Parse($data) $text = _JSON_Get($json, 'Data') ConsoleWrite($text)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now