1

I am currently working on a signup form and I want users to be pushed to my hubspot account upon sign up. The form is built in a .asp file format using HTML, CSS, and VBscript. I want the user to fill out all of the required fields and then send their responses to Hubspot using their Create Contact API endpoint.

The form itself is built out and working, now all I need to do is link up the API POST request. I am not familiar with VBscript or how one could go about sending JSON data to an API using VB. I started out by just trying to send dummy data that would be easily searchable figuring I can work on making the values dynamic later, but even this won't work. This is the code that I have written directly in the markup. Any help is appreciated!

<%
Dim objXmlHttpMain, URL, strJSONToSend

strJSONToSend = "{'properties': [{'property': 'email','value': '[email protected]'},{'property': 'firstname','value': 'Adrian'},{'property': 'lastname','value': 'Mott'},{'property': 'website','value': 'http://hubspot.com'},{'property': 'company','value': 'HubSpot'},{'property': 'phone','value': '555-122-2323'},{'property': 'address',},{'property': 'city','value': 'Cambridge'},'property': 'state','value': 'MA'},{'property': 'zip','value': '02139'}]}"

URL="https://api.hubapi.com/contacts/v1/contact/?hapikey=df670ac6-cc2d-452d-a571-11d0374e515e" 
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP") 
On Error Resume Next   
objXmlHttpMain.open "POST",URL, False
If Err Then       
  WScript.Echo Err.Description & " [0x" & Hex(Err.Number) & "]"
  WScript.Quit 1
End If
On Error Goto 0
objXmlHttpMain.open "POST",URL, False 
objXmlHttpMain.setRequestHeader "Accept", "application/json>"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing 
set objResult = nothing
%>
5
  • Where’s the question? Do you have a specific problem you need help with? Commented Jan 18, 2022 at 20:21
  • 2
    Replace single quotes in the json with double quotes. To do that in a vbscript string, you need to use two double quotes for one, like: strJSONToSend = "{""properties"":[{.....}" Commented Jan 20, 2022 at 3:27
  • Also check objXmlHttpMain.responseText after objXmlHttpMain.send Commented Jan 20, 2022 at 5:43
  • Does this answer your question? How to POST JSON Data via HTTP API using VBScript? Commented Jan 20, 2022 at 10:52
  • As @Flakes has pointed out your JSON that you are sending to the API endpoint isn't valid. You must use double quotes. Commented Jul 4, 2022 at 7:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.