1

I'm trying to run the following cURL request (as provided by Maxmind) within VBA:

curl -u "{user_id}:{license_key}" \
    "https://geoip.maxmind.com/geoip/v2.1/city/me?pretty"

Taking from other examples I've tried the following:

Sub maxmind_query()

Dim TargetURL As String
Dim HTTPReq As Object

TargetURL = "https://geoip.maxmind.com/geoip/v2.1/city/me"
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.Option(4) = 13056 '
HTTPReq.Open "PUT", TargetURL, False
HTTPReq.SetCredentials "XXXXX", "YYYYYYYY", 0
HTTPReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTPReq.send ("test[status]=" & Forms!curl!Text0.Value & "&test2[status]=" & Text2.Value)
MsgBox (HTTPReq.responseText)

End Sub

'''XXXX is my user id, YYYY my license key, removed for obvious reasons!

This errors at HTTPReq.send (runtime error 424 object required) which has me stumped.

I have no knowledge of cURL so despite a few days of research and blind attempts, I'm struggling to get anywhere with the above code.

I'm only experienced with VBA, and what I know is self taught, so be gentle....

If anyone is able to share their knowledge I'd be much obliged.

Further info provided by Maxmind:

http://dev.maxmind.com/geoip/geoip2/web-services/#Per-Service_URIs http://dev.maxmind.com/geoip/geoip2/web-services/#Command_Line_curl_Example

Many thanks!

PS. If I put the URL in a browser, input username and password into message box, the browser returns the required information, so I know the service and my credentials work. I guess my code isn't even getting that far though.

Smartbuild
  • 119
  • 3
  • 15
  • Given that you are using VBA, you might be better off using [MaxMind's Legacy API](http://dev.maxmind.com/geoip/legacy/web-services/). With the GeoIP2 API, you need to do basic authentication and then decode the JSON response. – Greg Oschwald Dec 27 '14 at 16:48
  • Thanks oschwald. This was my first approach, however this doesn't allow the Maxmind query to use the 'me' string instead of a specific IP address. – Smartbuild Dec 27 '14 at 17:29

1 Answers1

1

Got it working, here's my approach:

Sub Maxmind()

Dim MyRequest As Object

    Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
    MyRequest.Open "GET", _
    "https://geoip.maxmind.com/geoip/v2.1/city/me"

    MyRequest.SetCredentials "user", "password", 0

    ' Send Request.
    MyRequest.Send

    'And we get this response
    MsgBox MyRequest.ResponseText

End Sub

This was mainly copied from here here so thanks to previous contributors.

Hope it helps someone!

Community
  • 1
  • 1
Smartbuild
  • 119
  • 3
  • 15