1

Hi I'm calling an API and using the winhttp request and the GET method. I'm passing a json style parameter in the send method but it just can't get accepted. I end up with the error message:

{"code":"INS03","description":"Event ID required","requestId":"_181603230829162847306080","data":{},"validationErrors":null}

Which seems weird because I am indeed passing the event id parameter, as follows:

    inventory_URL = "https://api.stubhub.com/search/inventory/v1"

    Dim oRequest As WinHttp.WinHttpRequest
    Dim sResult As String

    Set oRequest = New WinHttp.WinHttpRequest
    With oRequest
        .Open "GET", inventory_URL, True
        .setRequestHeader "Authorization", "Bearer " & access_token
        .setRequestHeader "Accept", "application/json"
        .setRequestHeader "Accept-Encoding", "application/json"
        .send ("{""eventid"":""9445148""}")
        .waitForResponse
        sResult = .responseText
        Debug.Print sResult
        sResult = oRequest.Status
        Debug.Print sResult
   End With

Is there any issue with my code?

Thank you in advance,

Vadim

Daniel Dušek
  • 13,683
  • 5
  • 36
  • 51
  • I don't think it's going to change anything, but the parentheses around `.send ("{""eventid"":9445148}")` should be removed. See [this is confusing. why not just use parentheses all the time?](http://stackoverflow.com/documentation/vba/1179/procedure-calls/3818/this-is-confusing-why-not-just-always-use-parentheses#t=201608231909481978335) on Docs.SO for why this is eventually going to bite you in the rear end if you make it a habit. – Mathieu Guindon Aug 23 '16 at 19:10
  • Have you tried `.send "9445148"`? What does the API documentation says the URL is expecting? – Mathieu Guindon Aug 23 '16 at 19:12
  • I agree about the parentheses, also the pure .send "944518" might work, i didn't exactly do that but i found a work around by inserting the parameter directly into the inventory_URL string at the very top. I guess this API supports restful calls so for now i'll keep sticking to that. It's possible the .send "...." is the same technique from a different angle, thanks for the tips I really appreciate it, i'll keep a closer eye on the parenthesis habit ! – Vadim Serebrinskiy Aug 24 '16 at 17:25

1 Answers1

1

For GET request query string should be composed. Your data can't be passed in Send but in query string:

.Open "GET", inventory_URL & "?eventid=9445148", True

Check GET vs POST.

Daniel Dušek
  • 13,683
  • 5
  • 36
  • 51
  • yep that worked as well, i think that's the key issue i was tripping up on, I kept thinking I have to send something but now i see with GET there's no need it'll all be in the url string, thank you – Vadim Serebrinskiy Aug 24 '16 at 20:54