Link to home
Start Free TrialLog in
Avatar of cmccurdy
cmccurdyFlag for United States of America

asked on

JSON post with Access VBA

I need to convert the CURL POST command below to vba (access).  I'm very proficient with access vba but not anything web-based so any direction on learning materials would be also appreciated.  I found and modified an example that I thought might work (code below), but it just gives the error "ActiveX can't create the object.  Suggestions?

CURL COMMAND:
curl -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"shop": "9999999999","client_code": "88888888888.","lastname": "Ender","phonenumber": "5555555559","vehicle_year": "1999","vehicle_make": "JEEP","vehicle_model": "something" }' http://somewebsite.com/api/customers

VBA CODE (Fails with error above):

Private Sub cmdCreateAutoTextCustomer_Click()
Dim sURL As String, sHTML As String
Dim oHttp As Object
Dim Body As String
'‘Add a reference to the MSXML type library
Set oHttp = CreateObject("MSXML3.ServerXMLHTTP")

'‘The website to post to
sURL = "http://somewebsite.com/api/customers"

'‘ The json string to send.
Body = "{""shop_number"": ""9729925026"",""client_code"": ""142KukK231k."",""lastname"": ""Ender"",""phonenumber"": ""5555555559"",""vehicle_year"": ""2009"",""vehicle_make"": ""JEEP"",""vehicle_model"": ""something"" }"

oHttp.Open "POST", sURL, False
oHttp.setRequestHeader ' "Content - type", "application / json" '
oHttp.setRequestHeader '"Accept”, "application / json"'

'‘Send the json
oHttp.send (Body)

'‘Server response.
sHTML = oHttp.responseText

'‘Verify that the login was successful.
If Mid(sHTML, Len(sHTML) - 5, 6) = ":true}" Then
    MsgBox "Success"
    Set oHttp = Nothing
    MsgBox "An error occured."
Exit Sub
End If

Set oHttp = Nothing
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Darren
Darren
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmccurdy

ASKER

Thanks, I'm working on that now.