great77 Posted January 6, 2016 Share Posted January 6, 2016 I am having a problem with API authentication of LOGMEIN. . It is giving a message Not Authenticated. I checked the psk and company ID and they are correct. I have used the same credentials to get some info from their public APi, but in this case am having problem. This is the public API pdf link if someone can help me with the authentication.https://secure.logmein.com/welcome/documentation/EN/pdf/LogMeInCentralPublicAPIReference.pdf $restReq = ObjCreate("winhttp.winhttprequest.5.1") While 1 $file = FileOpen($MyFile, 2) $url = 'https://secure.logmein.com/public-api/v1/hosts? -H "Authorization:{\"companyId\":1cccsss43,\"psk\":\"00_\"}" -i -H "Content-Type:application/JSON; charset=utf-8" -H "Accept:application/JSON; charset=utf-8"' $restReq.Open("GET", $url, False) $restReq.Send() $oReceived = $restReq.ResponseText() $oStatusCode = $restReq.Status ;$file = FileOpen("Received.txt", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) Msgbox (0,"result", $oReceived) Msgbox (0,"result", $oStatusCode ) FileClose($file) $ Link to comment Share on other sites More sharing options...
trancexx Posted January 6, 2016 Share Posted January 6, 2016 With ObjCreate("winhttp.winhttprequest.5.1") .Open("GET", 'https://secure.logmein.com/public-api/v1/hosts') .SetRequestHeader("Authorization", '{"companyId":"1cccsss43","psk":"00_"}') .SetRequestHeader("Content-Type", 'application/json') .Send() MsgBox(4096, ".ResponseText", .ResponseText()) MsgBox(4096, "Status", .Status) EndWith great77 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
great77 Posted January 6, 2016 Author Share Posted January 6, 2016 Wow! Thank you so much Trancexx . It is perfectly working!!Cheers Link to comment Share on other sites More sharing options...
great77 Posted January 6, 2016 Author Share Posted January 6, 2016 With ObjCreate("winhttp.winhttprequest.5.1") .Open("GET", 'https://secure.logmein.com/public-api/v1/hosts') .SetRequestHeader("Authorization", '{"companyId":"1cccsss43","psk":"00_"}') .SetRequestHeader("Content-Type", 'application/json') .Send() MsgBox(4096, ".ResponseText", .ResponseText()) MsgBox(4096, "Status", .Status) EndWith Hi Tancexxx Please am querying this part ("GET", 'https://secure.logmein.com/public-api/v1/inventory/hardware/reports') and it is only given {"expires":null, "token:null},Any reason for this. Apologies to ask another question.... Link to comment Share on other sites More sharing options...
trancexx Posted January 6, 2016 Share Posted January 6, 2016 Sorry, I have no idea. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
great77 Posted January 7, 2016 Author Share Posted January 7, 2016 (edited) Sorry, I have no idea.This is the for the POST am getting error " status as 500, which seems to be server error and then encountered unexpected character h "ticket :"While 1 $file = FileOpen($MyFile, 2) $restReq = ObjCreate("winhttp.winhttprequest.5.1") $restReq.Open("POST", 'https://secure.logmein.com/public-api/v1/inventory/hardware/reports', False) $restReq.SetRequestHeader("Authorization", '{"companyId":"1143","psk":"00_ggphj"}') $restReq.SetRequestHeader("Content-Type", 'application/json; charset=utf-8') $restReq.SetRequestHeader("Accept", 'application/json; charset=utf-8')$spost = ' hostids=17473462, 1764856&fields=BatteryName, ServiceTag '; Performing the Request$restReq.Send($spost);$restReq.Send() MsgBox(4096, "Result", $restReq.ResponseTExt()) MsgBox(4096, "Status", $restReq.Status) Edited January 7, 2016 by great77 Link to comment Share on other sites More sharing options...
great77 Posted January 7, 2016 Author Share Posted January 7, 2016 (edited) This is the for the POST am getting error " status as 500, which seems to be server error and then encountered unexpected character h "ticket :" While 1 $file = FileOpen($MyFile, 2) $restReq = ObjCreate("winhttp.winhttprequest.5.1") $restReq.Open("POST", 'https://secure.logmein.com/public-api/v1/inventory/hardware/reports', False) $restReq.SetRequestHeader("Authorization", '{"companyId":"1143","psk":"00_ggphj"}') $restReq.SetRequestHeader("Content-Type", 'application/json; charset=utf-8') $restReq.SetRequestHeader("Accept", 'application/json; charset=utf-8')$spost = ' hostids=17473462, 1764856&fields=BatteryName, ServiceTag '; Performing the Request$restReq.Send($spost);$restReq.Send() MsgBox(4096, "Result", $restReq.ResponseTExt()) MsgBox(4096, "Status", $restReq.Status) Edited January 7, 2016 by great77 Link to comment Share on other sites More sharing options...
RyukShini Posted January 7, 2016 Share Posted January 7, 2016 ; The data to be sent - User Credentials etc here!! $sPD = 'hostids=17473462&1764856&fields=BatteryName&ServiceTag' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://secure.logmein.com/public-api/v1/inventory/hardware/reports", False) ; Post url $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") ; Header data > $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") ; Header data < ; Performing the Request $oHTTP.Send($sPD) ;Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived)Please reply with errors!If you want I can also put it in an array so you can input useranme/password or whatever post data you want to sent in .txt files, it may make life easier? Link to comment Share on other sites More sharing options...
great77 Posted January 7, 2016 Author Share Posted January 7, 2016 ; The data to be sent - User Credentials etc here!! $sPD = 'hostids=17473462&1764856&fields=BatteryName&ServiceTag' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://secure.logmein.com/public-api/v1/inventory/hardware/reports", False) ; Post url $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") ; Header data > $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") ; Header data < ; Performing the Request $oHTTP.Send($sPD) ;Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived)Please reply with errors!If you want I can also put it in an array so you can input useranme/password or whatever post data you want to sent in .txt files, it may make life easier?Thank you RyukShini. It is still similar to the unexpected error I had earlier as well. I changed the content-type and aceept to application/json and still gives the same error.Please see the error below. If I use GET request it gives OK as status and return token as null and expires as null. Please look at the link of the logmein documentation https://secure.logmein.com/welcome/documentation/EN/pdf/LogMeInCentralPublicAPIReference.pdf .{"message":"Unexpected error: The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.","ticket":"d336661457"}Any suggestion is highly appreciated. Link to comment Share on other sites More sharing options...
RyukShini Posted January 8, 2016 Share Posted January 8, 2016 Thank you RyukShini. It is still similar to the unexpected error I had earlier as well. I changed the content-type and aceept to application/json and still gives the same error.Please see the error below. If I use GET request it gives OK as status and return token as null and expires as null. Please look at the link of the logmein documentation https://secure.logmein.com/welcome/documentation/EN/pdf/LogMeInCentralPublicAPIReference.pdf .{"message":"Unexpected error: The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.","ticket":"d336661457"}Any suggestion is highly appreciated.; The data to be sent - User Credentials etc here!! $sPD = 'companyId=1143&psk=00_ggphj' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://secure.logmein.com/public-api/v1/authentication", False) ; Post url $oHTTP.SetRequestHeader("Authorization", '{"companyId":"1143","psk":"00_ggphj"}') $oHTTP.SetRequestHeader("Content-Type", 'application/json; charset=utf-8') $oHTTP.SetRequestHeader("Accept", 'application/json; charset=utf-8') ; Header data < ; Performing the Request $oHTTP.Send($sPD) ;Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) {"success":false} Thats all I get? Link to comment Share on other sites More sharing options...
great77 Posted January 8, 2016 Author Share Posted January 8, 2016 Mine is given {"success":true}. I am just looking at where something might be wrong. Link to comment Share on other sites More sharing options...
great77 Posted January 8, 2016 Author Share Posted January 8, 2016 expandcollapse popup$MyFile = @ComputerName & ".txt" While 1 $file = FileOpen($MyFile, 2) $sPD = 'hostids=17473462&1764856&fields=BatteryName&ServiceTag' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("post", "https://secure.logmein.com/public-api/v1/inventory/hardware/reports", False) ; Post url $oHTTP.SetRequestHeader("Authorization", '{"companyId":"1143","psk":"00_gphjxxxxxxxxxxxxxxxxx"}') $oHTTP.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") $oHTTP.SetRequestHeader("Content-Type", 'application/json; charset=utf-8') $oHTTP.SetRequestHeader("Accept", 'application/json; charset=utf-8') ;$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") ; Header data > ;$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") ; Header data < ; Performing the Request $oHTTP.Send($sPD) ;Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status MsgBox(4096, "Response code",$oReceived) If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.txt", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) ExitLoop WendThis one is giving error as :{"message":"Unexpected error: There was an error checking start element of object of type LMI.PublicApi.Inventory.DTO.CreateInventoryReportParameters. Encountered unexpected character 'h'.","ticket":"d337376614"} Link to comment Share on other sites More sharing options...
RyukShini Posted January 8, 2016 Share Posted January 8, 2016 Mine is given {"success":true}. I am just looking at where something might be wrong. the one giving success true, is that from what I gave you?If not please share the full code giving success true. Link to comment Share on other sites More sharing options...
great77 Posted January 8, 2016 Author Share Posted January 8, 2016 the one giving success true, is that from what I gave you?If not please share the full code giving success true.expandcollapse popup$MyFile = @ComputerName & ".txt" While 1 $file = FileOpen($MyFile, 2) $sPD = 'hostids=17473462&1764856&fields=BatteryName&ServiceTag' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("get", "https://secure.logmein.com/public-api/v1/authentication", False) ; Post url $oHTTP.SetRequestHeader("Authorization", '{"companyId":"1143","psk":"00_gphjxxxxxxxxxxxxxxxxx"}') $oHTTP.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") $oHTTP.SetRequestHeader("Content-Type", 'application/json; charset=utf-8') $oHTTP.SetRequestHeader("Accept", 'application/json; charset=utf-8') ;$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") ; Header data > ;$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") ; Header data < ; Performing the Request $oHTTP.Send() ;Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status MsgBox(4096, "Response code",$oReceived) If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.txt", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) ExitLoop Wend Link to comment Share on other sites More sharing options...
RyukShini Posted January 8, 2016 Share Posted January 8, 2016 expandcollapse popup$MyFile = @ComputerName & ".txt" While 1 $file = FileOpen($MyFile, 2) $sPD = 'hostids=17473462&1764856&fields=BatteryName&ServiceTag' ; Creating the object $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("get", "https://secure.logmein.com/public-api/v1/authentication", False) ; Post url $oHTTP.SetRequestHeader("Authorization", '{"companyId":"1143","psk":"00_gphjxxxxxxxxxxxxxxxxx"}') $oHTTP.SetRequestHeader("User-Agent", "User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") $oHTTP.SetRequestHeader("Content-Type", 'application/json; charset=utf-8') $oHTTP.SetRequestHeader("Accept", 'application/json; charset=utf-8') ;$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") ; Header data > ;$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") ; Header data < ; Performing the Request $oHTTP.Send() ;Download the body response if any, and get the server status response code. $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status MsgBox(4096, "Response code",$oReceived) If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.txt", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) ExitLoop Wend This is still giving me success false, not sure why? Link to comment Share on other sites More sharing options...
great77 Posted January 8, 2016 Author Share Posted January 8, 2016 May be you should not use application/json. Are you using logmein for your testing? 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