GithubHelp home page GithubHelp logo

vba-tools / vba-web Goto Github PK

View Code? Open in Web Editor NEW
2.0K 2.0K 490.0 100.12 MB

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web

Home Page: http://vba-tools.github.io/VBA-Web/

License: MIT License

Visual Basic 100.00%

vba-web's People

Contributors

berkus avatar damndam avatar ipopov001 avatar keyj avatar koenjanssenspd avatar mauriciojxs avatar mymuss avatar nextianovarum avatar nickswann avatar sdementen avatar sophist-uk avatar sylvaindesve avatar timhall avatar willayd avatar zippy1981 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vba-web's Issues

Update StackOverflow answers for VBA-Web

Mac Compatibility

This has been a great help. Unfortunately i am running into a compatibility issue on Mac OS due to the instantiation of the ActiveX Control MSXML2.ServerXMLHTTP.6.0.

Is there an alternative that is available that would be cross-platform?

Type Mismatch when parsing received JSON

The received JSON contained "Amount":14.6000000000, which was correctly parsed and given to CDbl for conversion. But it threw the mentioned error. I see a problem in usage of CDbl for converting the string to double because it's locale-dependent (my locale has ',' as decimal separator, which is of course nonsence to use in JSON). Using the Val for conversion solves this issue.

Add multiple Query String Param, same Key

Hi,

I am trying to add multiple QueryStringParam through AddQueryStringParam, this all works great unless I start adding params with the same Key. When adding multiple params with the same Key it only adds the latest one. I assume this is because AddQueryStringParam uses a dictionary and only unique Keys are allowed?

I have no problem editing the code but I was wondering if somebody reported this already or if you are adding it to 4.0?

Eg. Assume I send a GET request where I want to filter and only pull three fields, the current server I use accepts the following:

'Specify unique item
Request.AddQuerystringParam "Number", "123"
Request.AddQuerystringParam "Name", "Test Name"

'Specify which columns to pull
Request.AddQuerystringParam "Field", "Number"
Request.AddQuerystringParam "Field", "Name"
Request.AddQuerystringParam "Field", "OriginalAmount"

`Output should be something like:
`url/products?Number=123&Name=Test+Name&Field=Number&Field=Name&Field=OriginalAmount

`Output is:
`url/products?Number=123&Name=Test+Name&Field=OriginalAmount

BTW, again great REST script - very excited for 4.0.
Thanks!

OAuth1Authenticator improperly handles url and parameters

From http://oauth.net/core/1.0/#anchor14 the signature base string has very specific formatting for the request url and request parameters. This improper formatting caused issues with accessing the LinkedIn API.

Test against https://developer.linkedin.com/oauth-test-console

Todo:

  • Use OAuth1 formatting for request url (exclude query and hash, include port if not 80 or 443, lowercase protocol and host)
  • Use proper format and ordering for request parameters
  • Include explicit querystring parameters and implicit (included as part or Resource) with request parameters (including cachebreaker)

ParseJSON and Collections of Dictonaries

When encountering a json array of objects (ex [{key1:value, key2:value}, {key1:value, key2:value}]). The parser returns a collection of just the key values. This is due to the json_ParseArray function not checking for { before passing int json_ParseValue. I believe this could be resolved with a change to the json_ParseArray function (changes comment marked):

Private Function json_ParseArray(json_String As String, ByRef json_Index As Long, Optional json_ConvertLargeNumbersToString As Boolean = True) As Collection
    Set json_ParseArray = New Collection
    Dim json_Object As Dictionary 'New object for Dictionary handling

    json_SkipSpaces json_String, json_Index
    If VBA.Mid$(json_String, json_Index, 1) <> "[" Then
        Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting '['")
    Else
        json_Index = json_Index + 1

        Do
            json_SkipSpaces json_String, json_Index
            If VBA.Mid$(json_String, json_Index, 1) = "]" Then
                json_Index = json_Index + 1
                Exit Function
            ElseIf VBA.Mid$(json_String, json_Index, 1) = "," Then
                json_Index = json_Index + 1
                json_SkipSpaces json_String, json_Index
            End If

            'This check to see if the value is the start of an object
            If VBA.Mid$(json_String, json_Index, 1) = "{" Then
                Set json_Object = json_ParseObject(json_String, json_Index, json_ConvertLargeNumbersToString)
                json_ParseArray.Add json_Object
            Else
                json_ParseArray.Add json_ParseValue(json_String, json_Index, json_ConvertLargeNumbersToString)
            End If

        Loop
    End If
End Function

Execution behind Proxy Servers is not possible

In my Company a Proxy configuration script is set for IE.
At Home I use standard Internet with my Router.

The Example to get Google Directions is working fine at home, but when I'm in the Company I get a timeout, because the Code did not use the Windows / IE default proxy configuration.

This also cause me some issue to track the traffic with Fiddler.
As Fiddler is hooking in the proxy configuration, I asume Excel-REST is bypassing this with a direct internet connection only which doesn't work in my company environement.

Security Review

(Should be the last step before releasing v4.0.0)

Need to verify that VBA-Web is taking the right steps to be safe-by-default, but allows for adjusting security settings (e.g. self-signed certificates, #73)

Action items:

  • Enable certificate revocation check in WinHttpRequest (not available in cURL)
  • Disable automatic redirection in WinHttpRequest (disabled by default in cURL)
  • Add Insecure option for turning off SSL certificate validation

Remove Excel dependency with Application.OnTime

Hi Tim,
Outstanding job on VBA-Web! I love the simplicity as I use it to connect to web services on our internal software systems.

One suggestion is to remove the Application.OnTime dependency on Microsoft Excel. This works great in Excel, but not in other VBA-enabled applications like Microsoft Access.

As an alternative, I set up an additional class to utilize the Windows API for timer execution. I took advantage of a class (found here http://www.vbforums.com/showthread.php?527281-VB6-SelfTimer-class-module-2008-06-15) that even works without a wrapper in a standard module.

Using the timer class is a piece of cake. Just declare it withevents in WebAsyncWrapper and use the event to trigger the timeout functions.

Private WithEvents pTimer As SelfTimer  ' API timer class

Private Sub pTimer_Timer(ByVal Seconds As Currency)
    Call TimedOut
End Sub

This allows you to completely avoid the complexity of handling the returned timers in the standard module, and trying to sort the callbacks out to their calling instances.

Keep up the great work! I am really excited about this project, and will be using it extensively in the months ahead.

Large string support using StringBuilder

Hi Tim,
One of our web services had a very large response field (>1MB), which took several minutes to parse because of the way strings are reallocated when concatenated. I googled around and found an implementation of cStringBuilder.cls for JSONLib, and have merged the StringBuilder usage and some related JSONLib fixes into RestHelper.bas.

This JSONLib fixes and StringBuilder class came from http://code.google.com/p/vba-json/issues/detail?id=13.
I think StringBuilder initially came from http://www.vbaccelerator.com/home/VB/Code/Techniques/StringBuilder/article.asp,
and some fixes came from http://www.ediy.co.nz/vbjson-json-parser-library-in-vb6-xidc55680.html.

Is there a way to send you the updated RestHelpers.bas and cStringBuilder.cls without doing a Git fork and pull request?
Dean Wiles

Handling of empty values

Hi Tim,
Great project. I am building a client to a rest-server for sqlite database tables on it.

Just in case, I shall release my (poor) VBA soon along where the server is:
https://github.com/dkottow/g6-server

My "issue" was that I wanted empty cells to be mapped to nulls. To do that, I change the following in Module RestHelpers - maybe you agree..:

Private Function json_toString(ByRef Obj As Variant) As String

Select Case VarType(Obj)
    Case vbNull
        json_toString = "null"
    Case vbEmpty
        'dkottow check if the cell is empty to evtl. convert to null
        If IsEmpty(Obj) Then
            json_toString = "null"
        Else
            json_toString = """"""
        End If

Greetings, Daniel.

v4.0.0 Final Review

  • WebHelpers
  • WebClient
  • WebRequest
  • WebResponse
  • IWebAuthenticator
  • WebAsyncWrapper
  • DigestAuthenticator
  • EmptyAuthenticator
  • FacebookAuthenticator
  • GoogleAuthenticator
  • HttpBasicAuthenticator
  • OAuth1Authenticator
  • OAuth2Authenticator
  • TwitterAuthenticator
  • WindowsAuthenticator

ERROR - RestHelpers.ExecuteRequest: -2147012894

Running a large number of POST request from an Excel Sheet, and after around 3000 calls are encountering the above error.
I'm wondering if this is an out-of-memory error. Looking at the code, it seems possible that the Http object created in prepareHttpRequest is never garbage collected (not sure this is the right term to use in the MS/VBA world?). Maybe an explicit "Set Http = Nothing" is required in the Execute method?

Decoding GZIP web response

Hi Tim,
I really apreciate your effort in keeping Excel-Rest up-to-date.
Hope that my issue is a simple one.

I use a Web-Service returning a JSON String, but for performance it is GZIP encoded.
So I add a Header:
Request.AddHeader "Accept-Encoding", "gzip, deflate"

This works fine, so I get an gzip encoded response.
Now Im searching for a way how to decode this before it is handed over to the parser.

Regards
Stephan

Is it possible to use Excel-REST without Microsoft Scripting Runtime?

Thanks Tim!
Is it possible to run these classes without Microsoft Scripting runtime ?
I understand that the dependency is only for Scripting.Dictionary. So, providing a standalone Dictionary implementation is what I was thinking and removing dependency on Scripting.runtime.

I am trying to use Dictionary implementation as below - http://sysmod.wordpress.com/2011/11/24/dictionary-vba-class-update/
but currently running into following error -
"Private Object modules can not be used in public object modules as parameters or return types for public procedures, as public data members, or as public user defined types"

Anti-Issue

No issue, just wanted to say a big THANKS!

Wanted to produce some stats on my email usage and turned to CouchDB to hold the data as it uses a nice, simple REST interface & is lightweight for running on a single PC.

But trying to sort out JSON string issues AND PUT/POST, etc. was a pain.

It took me no time at all to get your "Excel" modules into Outlook and it works a dream. I push data from sent/recieved/changed emails to CouchDB with a simple web interface for viewing the stats showing me I'm averaging 70-110 incoming and around 20-30 outgoing emails per working day!

Next stage is a work management tool that lets me tag emails quickly pushing some details to CouchDB for a simple To Do type display with links back into the Outlook email items.

Couldn't do all of that without your help as there wouldn't be time - thanks again.
J.

Excel-REST on Microsoft Excel for Macintosh

Hi Tim,

Thanks for this great work.

I wanted to ask a question.

I made it work in Windows easily but for Mac OS I had the Dictionary problem. I downloaded the Dictionary implementation of yours but this time I am getting:

"Run-time error '429'
ActiveX component can't create object

error in Mac. In Windows everything is fine.

Any solutions/suggestions?

Regards,
Koray

Add a POST example

the get samples were very helpful but I am having issues processing a post request. I assume having a sample in hand would make things easier

content-length

Hi!
I try to put data with the help of AddBodyString to my request and the server isn't able to process it since the content-length is missing...

Am I supposed to use "AddParameter" with: "Content-Length" after having done "AddBodyString " or am I missing something different?

Thanks for the help!
Sebastian

Tweaks for Access-REST

Thanks Tim! This code is awesome and I was able to easily use it from Microsoft Access. We needed to enhance an old Access 2003 app to use a REST-based web service. In case anyone else needs to use Excel-REST from Access, here are the few tweaks I did:

  1. Exported RestHelpers.bas, HttpBasicAuthenticator.cls, IAuthenticator.cls, RestClient.cls, RestRequest.cls and RestResponse.cls, and then imported them into my Access project. Our web service only needed Basic authentication so I didn't bring over the others.
  2. Under Tools > References..., added a reference to "Microsoft XML, v6.0" so that it would compile the "MSXML2.DOMDocument" reference in RestHelpers/ParseXML. I wanted to verify that I could compile the whole project to ensure I didn't introduce any syntax issues that wouldn't be seen until runtime. It also needed the "Microsoft Scripting Runtime" reference.
  3. In RestHelpers/StartTimeoutTimer and StopTimeoutTimer, change Application.HWnd to Application.hWndAccessApp. This was the only syntactical difference that I encountered between the Excel and Access object models.
  4. In RestHelpers.bas / PrepareProxyForHttpRequest, the logging call threw an error because I passed in a ProxyServer, but no BypassList. The following code tweak made the BypassList truly optional:
    LogDebug "SetProxy: " & ProxyServer & ", " & IIf(IsMissing(BypassList), "", BypassList), "RestHelpers.PrepareProxyForHttpRequest"

Thanks again for sharing Excel-REST!
Dean.

Invalid certificate authority error for self-signed certificates

Attempting to access service with self-signed certificates throws the following: "The certificate authority is invalid or incorrect."

Will look into bypassing certificate checking in WinHttpRequest and cURL. If it's possible, default will remain checking the certificate with option added to override.

Add `LogRequest` and `LogResponse`

While adding LogDebug was helpful for logging what is happening inside Excel-REST, it can be a little noisy for understanding what was sent with a request and received with the response.

Re-thrown error descriptions are lost in Class methods on Mac

Example:

' In WebClient.cls
Public Function Execute(Request As WebRequest) As WebResponse
    On Error GoTo ErrorHandling

    ' An unknown error occurs or Err.Raise is used

ErrorHandling:
    ' Cleanup Execute
    ' Rethrow
    Err.Raise Err.Number, "WebClient.Execute", "An error occurred: ..."
End Function

' -> Error should be: "An error occurred: ..."
'    but it's generic: "Method 'Execute' of object 'WebClient' failed"

Parsing of json

Hi,

thanks for the nice work with this project; I have only played a little with it, but it seems really nice and useful. I have some trouble, though, extracting a json result.

I have something like

Dim client as new RestClient
Dim req As New RestRequest
req.BaseUrl = ...
req.resource = ...
req.Format = json
req.Method = httpGET
Dim resp As RestResponse: Set resp = client.Execute(req)

From the Immidiate window:

Debug.Print resp.Content
{
    "coef" : [
        0.34,
        -0.33,
        0.08
    ],
    "sigma2" : [
        0.95
    ]
}

But resp.Data is a collection with Item(1) = "coef" and Item(2) = "sigma2", rather than a dictionary with the parsed results.

Am I missing something obvious?

Office 2013 64-Bit Compile Issue

When I open the "VBA-Web - Blank.xlsm" file, I am getting an error

Compile error:
The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute.

It's specifically highlighting this line, and the "Function" word:
Private Declare Function utc_GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" _

I am running this on Windows 10, Excel version 15.0.4675.1000

Thanks! Looking forward to working with this, seems very useful!

Rest example

Fairly new to github, so not sure if I should put this here.

The rest example for GetDirection in the readme doesn't work. I get an automation error. The JSON one works fine. What I don't see in the Rest example is the base URL set anywhere

Google Analytics

It'd be awesome if you could provide an example of how to authenticate to the Google Analytics API, I've been trying to get it to work by modifying the example for Google Maps but without success.

Are you able to take a look?

Function GAClient() As RestClient
Set GAClient = New RestClient

' Set the base url for the service
'
' All requests will be appended to the base url
' e.g.
' BaseUrl = https://api.service.com/
' RequestA -> https://api.service.com/RequestA
' RequestB -> https://api.service.com/RequestB
'
GAClient.BaseUrl = "https://www.googleapis.com/auth/analytics.readonly"

End Function

Function MetricsRequest(ID As String, First As String, Last As String, Metrics As String) As RestRequest
Set MetricsRequest = New RestRequest
MetricsRequest.Resource = "metrics/{format}"

' Set the request format (Set {format} segment, content-types, and parse the response)
MetricsRequest.Format = json

' Replace any {...} url segments
' e.g. Resource = "resource/{id}"
' Request.AddUrlSegment("id", 123) -> "resource/123"

' Add parameters to the request (querystring for GET calls and body for everything else)
MetricsRequest.AddParameter "ids", ID
MetricsRequest.AddParameter "start-date", First
MetricsRequest.AddParameter "end-date", Last
MetricsRequest.AddParameter "metrics", Metrics

' (or force as querystring)


' (GET, POST, PUT, DELETE, PATCH)
MetricsRequest.Method = httpGET

' => GET https://maps.googleapis.com/maps/api/directions/json?origin=...&destination=...&sensor=false

End Function

Sub GetMetrics()
' Execute the request asynchonously and process later
GAClient.ExecuteAsync DirectionsRequest(""), "ProcessDirections"
End Sub

Public Sub ProcessMetrics(Response As RestResponse)
If Response.StatusCode = Ok Then
Dim Route As Dictionary
Set Route = Response.Data("routes")(1)("legs")(1)

    Debug.Print "Visits " & Route("ga:visits")("text") & _
        " to Bounces: " & Route("ga:bounces")("text")
End If

End Sub

Can't compile

I'm unable to get this to compile on Office 2010 x64 or Office 2013 x64. Anybody else having this issue?

Windows authentication

Hi,

I want to consume a service that runs on Windows authentication using Excel-REST. Is there a way to generate the authorization token using windows user ID and send it with the request to the REST service?

Curl authentication on MAC

I found a defect in the HTTPAuthenticator

On OS X the password should be escaped to deal with special characters to bash. For example, I had a "!" in my password with failed the call. In the WebAuthenticator_PrepareCurl method, I replaced:

Curl = Curl & " --basic --user " & Me.Username & ":" & Me.Password

with

Curl = Curl & " --basic --user " & Me.Username & ":" & Replace(Me.Password, "!", "\!")

Add Salesforce Example

Excerpt from recent request for assistance:

A couple of examples I am looking at to work with:
http://forceadventure.wordpress.com/2013/01/31/creating-a-custom-rest-api-in-salesforce/
This one provides the code on the SF end to serialize a SF standard object, say, the 'Account' object and provide it back to the requester. So assuming I set that up correctly, I 'just' need to set up the Excel-REST connector to be able to (1) authenticate with SF and (2) make that request/get that response!

http://wiki.developerforce.com/page/Getting_Started_with_the_Force.com_REST_API
This is the standard documentation SF provides on a similar example.

If you could provide an example of just how to send/retrieve a single standard object to/from SF, that would help immensely! I think this functionality is pretty generic and wouldn't be specific to your job but is generalizable to everybody who's looking for Excel<->SF integration. Right now I'm getting hung up on a basic step - what exactly should I be setting the 'callback url' in configuring the remote access screen (since I'm not creating a server application with Excel - there is no client-side callback url)

Error when reusing WebRequest object

When I'm trying to re-use the same WebRequest for multiple subsequent API calls. It fails with error.

I discovered that the Sub Prepare() duplicates headers every time Client.Execute() is called.
I fixed it by modifying the Prepare() with code to update the header [key,value] in case the key is already present.

Integer parameters - how to?

Tim,

Thanks for writing Excel-Rest, I am finding it great.

I have run into an issue, I hope you can point me in the right direction.

I want to set a parameter that is an integer, but

postRequest.AddParameter "myInteger", myInteger

gives a ByRef type compile error, since postRequest is expecting strings as parameters.

If I pass myInteger as a string the web service says it cant convert test to number.

I see you have an example of

postRequest.AddParameter "myInteger", 20

This compiles for me also (dont understand how this can work, but I have stopped asking "why" questions of Microsoft) but obviously a hard coded value is only useful in some cases.

Can you advise how to set a non string parameter?

Auto-proxy configuration

Hi Tim,

Thank you for this awesome project !

I wanted to share the solution I found in order to automatically configure proxies in WebClient 4.0 (WinHTTP)

This allows me to do something like this:

Dim APIClient as new WebClient
APIClient.BaseURL = "http://api.somewhere.net/"
autoProxy APIClient

The APIClient object receives automatically the appropriate proxy for the base URL.

This works by retrieving IE settings, including auto-detect and auto-config scripts, then performing a WPAD search for the Base URL.

https://gist.github.com/DamnDam/cb50ef081a27db4ebfb7

Adding multiple Authorization headers throws error

Throws the following (non-obvious) error:
-2147024713 (800700b7): Cannot create a file when that file already exists.

Resolve with addition of SetHeader (add/replace) alternative to AddHeader (add only)

Add SOAP support and/or example

Thinking of using your tool as soap request client. Do you have any feature request in the pipeline. I am planning to modify the RestClient to incorporate the soap calls - do you have any suggestions on the proposed approach.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.