jandings

WinHTTP Get (to a REST API): Authentication problem

1 post in this topic

#1 ·  Posted (edited)

Hello there,

I'm trying to query a REST API of a webservice, SHOPWARE to be precise. The API is very well documented (https://developers.shopware.com/developers-guide/rest-api/#using-the-rest-api-in-your-own-a) but only using PHP. I tried some stuff but could not make it work.

It should be very simple, because the following simply works in a Chrome-Browser:

https://USERNAME:PASSPHRASE@www.SHOPWAREDOMAIN.com/api/orders/300

queries me for username and passphrase and then dumps order number 300.

Now I try to do the same in AutoIt (based on the wonderful work of many contributors here):

#include-once
#include "..\INCLUDE\winhttp.au3"
#include "..\INCLUDE\OO_JSON.au3"


;Proxy Config
Global $oJSON = _OO_JSON_Init()
Global $obj = ""

Global $sUserName = "USERNAME"
Global $sPassword = "PASSPHRASE"
Global $sDomain = "www.SHOPWAREDOMAIN.com/api/orders/300"
Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) JOC/0.1") ; without ie proxy settings
$hConnect = _WinHttpConnect($hOpen, "https://" & $sDomain)
ConsoleWrite ($hConnect & "#")
$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sUserName & ":" & $sPassword & "@" & $sDomain, Default  )
;$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sDomain, Default,  $sUserName & ":" & $sPassword)
;$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sDomain, Default, , $sUserName & ":" & $sPassword )
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
; See what's returned
ConsoleWrite ($sReturned & "#" & @error)

Whatever version I use (I tried the commented ones and many others), I always get a reply from Shopware:

{"success":false,"message":"Invalid or missing auth"}

At least this comes from Shopware. But there must be some format of the credentials that I don't know or understand.

Any help?

Edited by jandings

Share this post


Link to post
Share on other sites



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

  • Similar Content

    • RyukShini
      By RyukShini
      Hello everyone.
      I would like to automate some things on my forum with AutoIT and so far I successfully logged in and everything seems to be going well, however this type of form I have no clue on how to make, I tried with a couple of different ideas and what not, but so far it wont work.
      I already found what I need for making unix timestamps and so on, so all I need is to understand how to make this in WINHTTP
      $sRead = _WinHttpSimpleFormFill($xConnect, "posting.php?mode=post&f=124", Default, "name:topic_seo_title", "testing my stuff before actually posting", "name:seo_desc", "testing my stuff before actually posting", "name:icon", "2", "name:subject", "testing my stuff before actually posting", "name:addbbcode20", "100", "name:message", "MoonBoys full video rips from popular porn sites", "name:post", "Submit", "name:fileupload", "Content-Type: application/octet-stream", "name:filecomment", "name:lastclick", $iUnixTime, "name:creation_time", $iUnixTime, "name:form_token", $uh) ------WebKitFormBoundaryPH Content-Disposition: form-data; name="topic_seo_title" testing my stuff ------WebKitFormBoundaryPH Content-Disposition: form-data; name="seo_desc" testing my stuff ------WebKitFormBoundaryPH Content-Disposition: form-data; name="seo_key" ------WebKitFormBoundaryPH Content-Disposition: form-data; name="icon" 2 ------WebKitFormBoundaryPH Content-Disposition: form-data; name="subject" testing my stuff ------WebKitFormBoundaryPH Content-Disposition: form-data; name="addbbcode20" 100 ------WebKitFormBoundaryPH Content-Disposition: form-data; name="message" [center][b]testing this[/b] [i][b]test: test: [neon=Pink]Screenshots:[/neon] test Details:[/b][/i][/center] ------WebKitFormBoundaryPH Content-Disposition: form-data; name="post" Submit ------WebKitFormBoundaryPH Content-Disposition: form-data; name="fileupload"; filename="" Content-Type: application/octet-stream ------WebKitFormBoundaryPH Content-Disposition: form-data; name="filecomment" ------WebKitFormBoundaryPH Content-Disposition: form-data; name="lastclick" 1488467908 ------WebKitFormBoundaryPH Content-Disposition: form-data; name="creation_time" 1488467908 ------WebKitFormBoundaryPH Content-Disposition: form-data; name="form_token" 4ee1f6e9f21d7147f31a94d16bb16eaddf7bb3e8 ------WebKitFormBoundaryPHhcKRBLEwtQXIqY--  
    • luckyluke
      By luckyluke
      Hello all,
      Im trying to get the information from https website, but it does not return any thing, here is the code:
      Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
      $agent ='Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'
      $url = "https://www.sportinglife.com/racing/results"
      $oHTTP.Open("GET", $url, False)
      $oHTTP.setRequestHeader ("User-Agent", $agent)
      $oHTTP.Option(4) = 13056
      $oHTTP.Send()
      $src = ($oHTTP.ResponseText)
      ConsoleWrite($url & @CRLF)
      MsgBox(0, '$src', $src)
      when i tried with other website, it is working, but this code does not works with this website. Pls help me
      thank you.
    • thang0408
      By thang0408
      Hi there,
      I'm trying to send a simple get request by ObjCreate("winhttp.winhttprequest.5.1")
      But it can only work on some computer, and it can't send request on other computer.
      I guess the problem is some computer have the different version of winhttp request (not 5.1, higher or lower)
      Can I send a get request without using winhttp?
      Thanks for your help!
    • CT83
      By CT83
      (Sorry if this topic is in the wrong section, please suggest a better place if so.)
      Hi! a newbie here, since a few weeks i have got the basic hang of Pixelsearch, Controlclick, Imagesearch functions and now would like to proceed to Automating Internet navigation.
      In this case i am trying to develop a Script which will keep a watch on amazon page and notify me when the price of a commodity drops. I can program the latter part but i still am in search of a better way to , navigate and basically watch webpages with out actually having them on the screen
      Therefore, I need some guidance with HttpRequest, and Winhttp functions, can anyone please refer me to tutorials, links and example scripts for a complete noobbie? Some detailed Video Tutorials, and Guides would just be icing on the cake.
      Sorry, if this sounds too naive. Hoping for positive replies
       
       
    • ntprohd
      By ntprohd
      how to login to google with winhttp in AutoIt