Access denied for XMLHTTP60 request, how to debug and fix? RRS feed

  • Question

  • Hi all, I'm quite new to VBA, having experience in javascirpt, php, python mostly.

    I need to fetch some json data from an internal corporate endpoint, and I am trying to make the basic below code running. However I get "Access is denied" error '-2147024891 (80070005)' as described in the attached picture.

    The token I am sending via the "x-access-token" header is correct, and works perfectly on Postman, but on Excel VBA I get this error.

    Do you have any idea why? Is there a way I can debug the request (with all headers) I am sending, to understand if the access token is actually passed to the request?

    Thanks in advance!

    Sub basic_get()
        Dim req As New MSXML2.XMLHTTP60
        Dim reqURL As String
        Dim status As Integer
        Dim token As String
        'reqURL = "https://jsonplaceholder.typicode.com/posts"
        reqURL = "internal endpoint here"
        token = "token here"
        req.Open "GET", reqURL, False
        req.setRequestHeader "x-auth-token", token
        req.setRequestHeader "Content-Type", "application/json'"
        status = req.status
        If status <> 200 Then
            Debug.Print "Error - Exiting this Sub"
            Exit Sub
        End If
        'Debug.Print req.responseText
        Debug.Print req.getAllResponseHeaders()
    End Sub

    Thursday, September 17, 2020 12:58 PM

All replies