cmccurdy
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.Serve rXMLHTTP")
'‘The website to post to
sURL = "http://somewebsite.com/api/customers"
'‘ The json string to send.
Body = "{""shop_number"": ""9729925026"",""client_co de"": ""142KukK231k."",""lastnam e"": ""Ender"",""phonenumber"": ""5555555559"",""vehicle_y ear"": ""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
CURL COMMAND:
curl -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"shop": "9999999999","client_code"
VBA CODE (Fails with error above):
Private Sub cmdCreateAutoTextCustomer_
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.Serve
'‘The website to post to
sURL = "http://somewebsite.com/api/customers"
'‘ The json string to send.
Body = "{""shop_number"": ""9729925026"",""client_co
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER