JSON post with  Access VBA

cmccurdy
cmccurdy used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Commented:
Hi,

What is the error you are getting and what are you getting back in the response?

What does
oHttp.responseText

Open in new window

output

Does this work?
oHttp.responseXML.xml

Open in new window

From your previous question that I answered you were failing on the create object. This is now working so you might have to debug the oHttp object to see what you are receiving back.

Thanks,

Darren

Author

Commented:
Thanks, I'm working on that now.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial