Post JSON to web in excel vba Post JSON to web in excel vba vba vba

Post JSON to web in excel vba


JSON can be very sensitive to how it's formatted, so I would make sure everything is quoted properly before it is sent. I would recommend splitting Body into a separate variable and debugging the value with http://jsonformatter.curiousconcept.com/ before sending.

Dim Body As StringBody = "{""mType"":""OPEN_SYSTEM_TRADE"",""systemOwnerId"":10}"' Set breakpoint here, get the Body value, and check with JSON validatoroHttp.Send Body

I ran into many similar issues when working with Salesforce's REST API and combined my work into a library that may be useful to you: https://github.com/VBA-tools/VBA-Web. Using this library, your example would look like:

Dim Body As New DictionaryBody.Add "mType", "OPEN_SYSTEM_TRADE"Body.Add "systemOwnerId", 10Dim Client As New WebClientDim Response As WebResponseSet Response = Client.PostJson("somewebsite.com", Body)Worksheets("Open1").Range("A1").Value = Response.Content