Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am trying to use VBA-Web for submitting REST API via Excel VBA and running into issues

GitHub - VBA-tools/VBA-Web: VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web[^]

VB
Private Sub Worksheet_Activate() 
Dim Client As New WebClient 
Dim Request As New WebRequest 

Client.TimeoutMs = 30000 ' 30 seconds

Client.BaseUrl = "https://postman-echo.com/basic-auth"
'Client.BaseUrl = "https://rest.reviso.com/customers?demo=true"
Request.Format = WebFormat.Json

Dim Auth As New HttpBasicAuthenticator
Auth.Setup _
Username:="postman", _
Password:="password"


Dim Response As WebResponse
Set Response = Client.Execute(Request)

If Response.StatusCode <> Ok Then
    Sheets("Test").Range("A1") = Response.StatusDescription
    Exit Sub
End If

Dim Json As Object
Set Json = WebHelpers.ParseJson(Response.Content)

FillData Json
End Sub


Thanks!

What I have tried:

I tried to modify this example to use HttpBasicAuthenticator but unsuccessful it says HTTP error 401. When I use Postman to submit the rest request it is fine.

api-samples/rest/excel at master · revisohq/api-samples · GitHub[^]

If I use this Url that does not need to authenticate. It works as expected

https://rest.reviso.com/customers?demo=true[^]
Posted
Updated 4-Jul-19 20:35pm
v2
Comments
F-ES Sitecore 5-Jul-19 3:48am    
Use a tool like fiddler to examine the network calls. Compare the call made from your code vs the one made my postman and look for differences.
Member 10093180 5-Jul-19 4:06am    
Thanks for your comment. I tried using Fiddler and the VBA request made did not showed up in the Debugger. Where as Postman did. Any reason why?
F-ES Sitecore 5-Jul-19 4:18am    
It might be to do with proxy settings as fiddler sets itself up as a proxy and the VBA code might ignore proxy settings. You can use wireshark instead which works at the network level and captures everything going through the network driver. It's not as user friendly as fiddler though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900