0

I am working on making a report for my company that takes values from a GET API request and cross compares received values against values received from elsewhere. The problem I am facing is that the GET request works perfectly on Postman but returns response as though the body I am attaching is not reaching the server when I send the same request through VBA. The body attached with the request is needed to indicate from which date to which date and other details needed by the server to filter the response and without it the response is identical to what I am receiving now, so I am fairly certain this is the issue but I don't know how to force VBA to send the body along with a GET request.

JsonAddBody = Digi.Cells(1, 27).Value
Debug.Print JsonAddBody

'{"tenantId": "100002","startDate":"2021-08-22","endDate":"2021-08-23"}

JsonAddBodyLen = Digi.Cells(2, 27).Value
Debug.Print JsonAddBodyLen
'______________________________________________________________
'URL and other settings for HTTP request
Url = "http://rms.digitory.com:300/Details"

Set hReq = CreateObject("MSXML2.XMLHTTP")
    With hReq
        .Open "GET", Url, False
        .setRequestHeader "Authorization", "Bearer " & authKey
        .setRequestHeader "User-Agent", "Mozilla 5.0"
        .setRequestHeader "Accept", "application/json"
        .setRequestHeader "Content-type", "application/json"
        .setRequestHeader "Content-Length", "" & JsonAddBodyLen
        .send (JsonAddBody)
    End With
  • 1
    `GET` requests shouldn't really have a body, you can send it but it shouldn't have a meaning. See: https://stackoverflow.com/a/983458/4839827. Are you sure this is a `GET` request, and not a `POST`? – Ryan Wildry Aug 27 '21 at 15:30
  • Where and how are you checking the response? If you're using `Debug.Print` you should be aware that only displays around 200 lines, and the rest will be cut off... What response are you getting? – Tim Williams Aug 27 '21 at 16:06
  • If you have parameters for the GET request, you're probably supposed to add them into the URL or the headers section, like `"http://rms.digitory.com:300/Details&tenantId=100002&startDate=20210822&endDate=20210823"`. This is just a guess. – Toddleson Aug 27 '21 at 21:25
  • If it works in POSTMAN then maybe the request is fine but the response is the issue. The XMLHTTP object stores response data in 3 different properties. `.Status`, `.responsetext`, and `.statustext`. You may need to check all 3. – Toddleson Aug 27 '21 at 21:31

0 Answers0