Jump to content

Recommended Posts

Posted (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

 

image.png.3f3a94a6a6079ee9060862441cd63414.png

I only want the data...

I have a URL and an authorization key but not having any luck...

 

get_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 by goodmanjl531
update question
Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...