Veerababu Posted June 9, 2021 Share Posted June 9, 2021 HI Team, As BeyondTrust API using POST, GET methods in different program languages (C++,Java, Python, Powershell). is there any way to use AutoIT to use the same. Apricated for your help. Thank you Link to comment Share on other sites More sharing options...
Veerababu Posted June 9, 2021 Author Share Posted June 9, 2021 Example: Powershell Powershell $headers = @{ Authorization="PS-Auth key=c479a66f…c9484d; runas=doe-main\johndoe;"; }; $uri = " /Auth/SignAppin"; $signinResult = Invoke-RestMethod -Uri $uri -Method POST -Headers $headers -SessionVariable script:session; $uri = " /ManagedAccounts"; $accounts = Invoke-RestMethod -Uri $uri -Method GET -WebSession $script:session -Headers $headers; Link to comment Share on other sites More sharing options...
Danp2 Posted June 9, 2021 Share Posted June 9, 2021 You may want to check out the WinHTTP UDF. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Veerababu Posted June 9, 2021 Author Share Posted June 9, 2021 HI Dan, i got below AutoIT code, however getting error like ( SEND ERROR : (0x80020009) The host name in the certificate is invalid or does not match. #include "WinHttp.au3" post_authentication_test() Func post_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 POST request $hrequest = .Open("POST", "https://<Domain>/BeyondTrust/api/public/v3/Auth/SignAppin", False) ;Set request headers and options .SetRequestHeader( "Content-Type", "application/json") .SetRequestHeader( "authorization", "PS-Auth key=<API Key>; runas=<API User>; pwd=[<Password>];") ;Send request .Send($hrequest) 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) Return EndFunc Link to comment Share on other sites More sharing options...
JockoDundee Posted June 9, 2021 Share Posted June 9, 2021 2 hours ago, Veerababu said: HI Dan, i got below AutoIT code, however getting error like ( SEND ERROR : (0x80020009) Maybe ask @Homoud or @LtNeno? Also, I know @TheXman’s code when I see it. TheXman 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
TheXman Posted June 9, 2021 Share Posted June 9, 2021 1 minute ago, JockoDundee said: Maybe ask @Homoud or @LtNeno? That was exactly what I was thinking when I saw the post earlier this morning. 🤣 2 minutes ago, JockoDundee said: Also, I know @TheXman’s code when I see it. That's hilarious! So not only do I recognize my code when I see it, but now you do too. 🤣 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
TheXman Posted June 9, 2021 Share Posted June 9, 2021 (edited) 5 hours ago, Veerababu said: The host name in the certificate is invalid or does not match. That is a very explicit error message. To fix it, you have several options. Here are a few: If you have a host name that has a valid SSL certificate, then use it. (i.e. https://some.example.com/...) If you don't have a host name with a valid SSL certificate: Set the Option property of the WinHttpRequest object to ignore the SSL error. or Get an SSL certificate for the host name that you are using and install it on the web server. Use HTTP instead of HTTPS, if it's an option (only for testing of course ) Edited June 9, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
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