chaoticyeshua Posted September 13, 2019 Share Posted September 13, 2019 (edited) Hello, I was approved for a v5 Dell TechDirect API key and am having some issues that I was hoping to receive some input on. My code is designed to retrieve warranty information through Dell's API for computers in our inventory as a part of our imaging process. Our existing code for their v4 API is working perfectly, but they recently made some changes to their process. Now, we are given an API key and a client secret, and we must use those to generate a token which expires every hour. I'm having what I consider to be an odd issue which makes the script, as we have historically used it, extremely problematic. First, the code itself (note that there's obviously more code than this, but this is enough to demonstrate the issue): ;First we need to get the token ;Create HTTP Object Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHttp.Option(9) = 0x800 ;Open a POST request at the api. The 'False' is because we are opening the request synchronously $oHTTP.Open("POST", "https://apigtwb2c.us.dell.com/auth/oauth/v2/token", False) ;We need to set the content-type because our credentials are being sent in like a form $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ;In case the client_id or the client secret changes, here is where you would change them Local $client_id = "myapikey" Local $client_secret = "myclientsecret" ;Lastly we need to send the request, the string parameter is the credentials we are sending in. $oHTTP.Send('grant_type=client_credentials&client_id=' & $client_id & '&client_secret=' & $client_secret) When the code was first written, it worked fine on the computer it was initially run on. Once the code was being tested by someone else on their computer, they received the following error: "No credentials were available in the client certificate" Upon reading into the issue, it seems that winhttp objects use the first cert in the "CURRENT_USER\My" store for some purpose unknown to us. The error itself seemed to be resolved by adding the line $oHttp.SetClientCertificate("CURRENT_USER\My\mycert") and pointing to a specific cert in the store (in our case, replace the "mycert" signature with the user's email address). However, we typically run this script as a local user account, rather than under a user's domain account, as a part of our computer imaging process. We are unable to make this script work under a local user account, and we aren't sure why pointing to a cert is even required. It doesn't seem to me that it should be. Is there anyone out there with more knowledge that can point us in the right direction to make this work under a local user account? Edit: FYI, I have already reached out to Dell and they just said they can't help me. Edited September 13, 2019 by chaoticyeshua Link to comment Share on other sites More sharing options...
mLipok Posted September 16, 2019 Share Posted September 16, 2019 Try to use HTTP.au3 Or post what com error handler say to you. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
AriK4 Posted November 7, 2019 Share Posted November 7, 2019 Hello chaoticyeshua, Were you able to figure this out? I'm also trying to make the transition to the new API and even contacted Dell for some sample code, but they weren't able to provide anything. Thanks, Ari. Link to comment Share on other sites More sharing options...
JoeBar Posted November 14, 2019 Share Posted November 14, 2019 (edited) You can see my post if it can help. https://www.autoitscript.com/forum/topic/84133-winhttp-functions/page/46/?tab=comments#comment-1440463 Edited November 14, 2019 by JoeBar Link to comment Share on other sites More sharing options...
5g6tdcv4 Posted November 18, 2021 Share Posted November 18, 2021 (edited) Not pretty, but you can create a functional warranty lookup from it. expandcollapse popup#include <HTTP.au3> $url = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token" $postdata = "client_id=" & "YOURID" & "&" & "client_secret=" & "YOURSECRET" & "&" & "grant_type=client_credentials" $test = _HTTP_Post1($url, $postdata) ConsoleWrite($test) ;this consolewrite will show you your new token if its older than an hour $token ="3997b2f1-1781-426d-bc1f-bd7e0bd9011f" ;will need to be updated with latest token $ans = _http_get1("https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements?servicetags=YOUR SERIAL") MsgBox(0,"",$ans) Func _HTTP_Post1($url, $postdata = '') Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $url, False) If @error Then Return SetError(1, 0, 0) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($postdata) If @error Then Return SetError(2, 0, 0) Local $sReceived = $oHTTP.ResponseText Local $iStatus = $oHTTP.Status If $iStatus = 200 Then Return $sReceived Return SetError(3, $iStatus, $sReceived) EndFunc ;==>_HTTP_Post Func _HTTP_Get1($url) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") Local $res = $oHTTP.Open("GET", $url, False) If @error Then Return SetError(1, 0, 0) #forceref $res $oHTTP.SetRequestHeader("Content-Type", "application/json") $oHTTP.SetRequestHeader("Authorization", "Bearer " &$token) $oHTTP.Send() If @error Then Return SetError(2, 0, 0) Local $sReceived = $oHTTP.ResponseText Local $iStatus = $oHTTP.Status If $iStatus = 200 Then Return $sReceived Return SetError(3, $iStatus, $sReceived) EndFunc ;==>_HTTP_Get Edited November 18, 2021 by Jos added codebox... please use <> next time. Link to comment Share on other sites More sharing options...
Valnurat Posted January 26 Share Posted January 26 Hi. I'm trying to run the code, but I get an error: can't open include file <HTTP.au3>. Where can I find the HTTP.au3? Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Musashi Posted January 26 Share Posted January 26 (edited) 37 minutes ago, Valnurat said: Where can I find the HTTP.au3? Try : https://github.com/jesobreira/HTTP.au3/blob/master/README.md and : Edited January 26 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Valnurat Posted January 26 Share Posted January 26 Thank you. I have downloaded it and I have added my own client-ID and the client-secret, but I get some errors. We intercepted a COM Error ! Number is: 80020009 Windescription is: Exception occurred. 0We intercepted a COM Error ! Number is: 80020009 Windescription is: Exception occurred. Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Musashi Posted January 26 Share Posted January 26 14 minutes ago, Valnurat said: I have downloaded it and I have added my own client-ID and the client-secret, but I get some errors. You could have a look at the WinHttp.au3 from @trancexx . However, the commands would then have to be adapted accordingly. https://github.com/dragana-r/autoit-winhttp/blob/master/WinHttp.au3 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 Is that because the http.au3 is not working? Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 27 Developers Share Posted January 27 (edited) Include this info in the error message you get and show the result on error: Global $__g_oHTTP_ErrorHandler = ObjEvent("AutoIt.Error", __HTTP_OnError) ; Install a custom error handler ; Custom error handler will set @error variable to 1 if a COM error is intercepted ; and will print out the error informations by the Console Func __HTTP_OnError(ByRef $oMyError) Local $HexNumber = Hex($oMyError.number, 8) ConsoleWrite("We intercepted a COM Error !" & @LF & _ "Number is: " & $HexNumber & @LF & _ "Windescription is: " & $oMyError.windescription _ "err.description is: " & $oMyError.description _ ) Return SetError(5, $HexNumber, 0) EndFunc ;==>__HTTP_OnError Edited January 27 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 Ok, but the number is just 0, I guess or then I don't understand how I should use the function. Sorry. 😳 Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 27 Developers Share Posted January 27 Update the http.au3 code! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 Did that, but still the same error. Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 27 Developers Share Posted January 27 sigh.... of course you still get the same error, but there should be more information now! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 Sorry, but how should I add the function? 😳 Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 If I just add it like this: expandcollapse popup#include <HTTP.au3> Global $__g_oHTTP_ErrorHandler = ObjEvent("AutoIt.Error", __HTTP_OnError) ; Install a custom error handler $url = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token" $postdata = "client_id=" & "API-ID" & "&" & "client_secret=" & "API-SECRET" & "&" & "grant_type=client_credentials" $test = _HTTP_Post1($url, $postdata) ConsoleWrite($test) ;this consolewrite will show you your new token if its older than an hour $token ="3997b2f1-1781-426d-bc1f-bd7e0bd9011f" ;will need to be updated with latest token $ans = _http_get1("https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements?servicetags=845vls3") MsgBox(0,"",$ans) ; Custom error handler will set @error variable to 1 if a COM error is intercepted ; and will print out the error informations by the Console Func __HTTP_OnError(ByRef $oMyError) Local $HexNumber = Hex($oMyError.number, 8) ConsoleWrite("We intercepted a COM Error !" & @LF & _ "Number is: " & $HexNumber & @LF & _ "Windescription is: " & $oMyError.windescription _ "err.description is: " & $oMyError.description _ ) Return SetError(5, $HexNumber, 0) EndFunc ;==>__HTTP_OnError Func _HTTP_Post1($url, $postdata = '') Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $url, False) If @error Then Return SetError(1, 0, 0) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($postdata) If @error Then Return SetError(2, 0, 0) Local $sReceived = $oHTTP.ResponseText Local $iStatus = $oHTTP.Status If $iStatus = 200 Then Return $sReceived Return SetError(3, $iStatus, $sReceived) EndFunc ;==>_HTTP_Post Func _HTTP_Get1($url) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") Local $res = $oHTTP.Open("GET", $url, False) If @error Then Return SetError(1, 0, 0) #forceref $res $oHTTP.SetRequestHeader("Content-Type", "application/json") $oHTTP.SetRequestHeader("Authorization", "Bearer " &$token) $oHTTP.Send() If @error Then Return SetError(2, 0, 0) Local $sReceived = $oHTTP.ResponseText Local $iStatus = $oHTTP.Status If $iStatus = 200 Then Return $sReceived Return SetError(3, $iStatus, $sReceived) EndFunc ;==>_HTTP_Get I'll get the below error: "C:\Users\DKent\Autoit\DellAPI\DellAPI.au3"(15,37) : error: __HTTP_OnError() already defined. Func __HTTP_OnError(ByRef $oMyError) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\DKent\Autoit\DellAPI\DellAPI.au3"(20,35) : error: syntax error "err.description is: " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Users\DKent\Autoit\DellAPI\DellAPI.au3 - 2 error(s), 0 warning(s) Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 27 Developers Share Posted January 27 (edited) Yes of course you get that. So we are 13 years further and you don't know any basics at all and simply copy paste code in the hope this work and then dump it here so we can solve these simple things for you? Get rid of the #include when you hardcode the funcs in your own script and the second error is a simple basic mistake you really should be able to figure out. This code is error free according au3check.... expandcollapse popupGlobal $__g_oHTTP_ErrorHandler = ObjEvent("AutoIt.Error", __HTTP_OnError) ; Install a custom error handler $url = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token" $postdata = "client_id=" & "API-ID" & "&" & "client_secret=" & "API-SECRET" & "&" & "grant_type=client_credentials" $test = _HTTP_Post1($url, $postdata) ConsoleWrite($test) ;this consolewrite will show you your new token if its older than an hour $token ="3997b2f1-1781-426d-bc1f-bd7e0bd9011f" ;will need to be updated with latest token $ans = _http_get1("https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements?servicetags=845vls3") MsgBox(0,"",$ans) ; Custom error handler will set @error variable to 1 if a COM error is intercepted ; and will print out the error informations by the Console Func __HTTP_OnError(ByRef $oMyError) Local $HexNumber = Hex($oMyError.number, 8) ConsoleWrite("We intercepted a COM Error !" & @LF & _ "Number is: " & $HexNumber & @LF & _ "Windescription is: " & $oMyError.windescription & _ "err.description is: " & $oMyError.description _ ) Return SetError(5, $HexNumber, 0) EndFunc ;==>__HTTP_OnError Func _HTTP_Post1($url, $postdata = '') Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $url, False) If @error Then Return SetError(1, 0, 0) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($postdata) If @error Then Return SetError(2, 0, 0) Local $sReceived = $oHTTP.ResponseText Local $iStatus = $oHTTP.Status If $iStatus = 200 Then Return $sReceived Return SetError(3, $iStatus, $sReceived) EndFunc ;==>_HTTP_Post Func _HTTP_Get1($url) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") Local $res = $oHTTP.Open("GET", $url, False) If @error Then Return SetError(1, 0, 0) #forceref $res $oHTTP.SetRequestHeader("Content-Type", "application/json") $oHTTP.SetRequestHeader("Authorization", "Bearer " &$token) $oHTTP.Send() If @error Then Return SetError(2, 0, 0) Local $sReceived = $oHTTP.ResponseText Local $iStatus = $oHTTP.Status If $iStatus = 200 Then Return $sReceived Return SetError(3, $iStatus, $sReceived) EndFunc ;==>_HTTP_Get Edited January 27 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 (edited) Thank you again I can now see more detalis than before. "There were no credentials available for the client certificate" and that's funny, but maybe my credetials is wrong, but they shouldn't be. Edited January 29 by Valnurat Yours sincerely Kenneth. Link to comment Share on other sites More sharing options...
Valnurat Posted January 27 Share Posted January 27 And sorry for what I missed. It was in the http.au3 you meant I needed to update and not in my code. Sorry for that. Yours sincerely Kenneth. 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