VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
1.99k stars 493 forks source link

Having array in QueryStringParameters #153

Closed mauriciojxs closed 9 years ago

mauriciojxs commented 9 years ago

Hi Tim,

This is more a question than an issue with your code.

I successfully used your app with Client.GetJson((Resource)) (while Resource is the string appended to the API URL) to get information from TODOist API. This is the posted URL:

GET https://todoist.com/API/v6/sync?token=MY_TOKEN_HERE&seq_no=4595849276&seq_no_global=4595849276&resource_types=["projects"]

Now I'm trying to do the same, while making use of the WebRequest functions, but I'm stuck in the resource_types= parameter, as it asks for an array. I tried adding this to the body, instead of the querystring, but the API won't accept. Bottom line, is there a way to have arrays appended to the querystring, rather than the body? Below is a copy of the code that is NOT working:

Dim Request As New WebRequest
    Request.Resource = "sync"
    Request.Method = WebMethod.Httpget
    Request.Format = WebFormat.Json

 Dim Body As New Dictionary
    Request.AddQuerystringParam "seq_no", 0
    Request.AddQuerystringParam "seq_no_global", 0
    Request.AddQuerystringParam "token", cfg.Project.Token

    Body.Add "resource_types", Array("projects")
    Set Request.Body = Body

    Set Response = cfg.Project.Client.Execute(Request)

Thanks for any help with that! Mauricio

timhall commented 9 years ago

I intentionally left out array support in querystrings and url-encoded as there is no accepted standard (and the generally used form doesn't match TODOist, so it probably wouldn't work anyways).

For you case, I would try the following:

Dim ResourceTypes As String
ResourceTypes = "[""" & Join(Array("projects"), """, """) & """]"
' or directly with "[""projects""]"
Request.AddQuerystringParam "resource_types", ResourceTypes

http://api.jquery.com/jquery.param/ (Includes notes and traditional setting) http://stackoverflow.com/questions/6243051/how-to-pass-an-array-within-a-query-string

mauriciojxs commented 9 years ago

In both the links you mention, there are references to arrays in the string. Is there an equivalent of the "serialize" in your library? Besides this [projects] call there are a number of other commands I should pass in the same format.

EDIT: sorry, just tested it and the "join" you proposed will work perfectly.