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': 'testingapis@hubspot.com'},{'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
%>
user692942
  • 16,398
  • 7
  • 76
  • 175
alias542
  • 11
  • 1
  • Where’s the question? Do you have a specific problem you need help with? – user692942 Jan 18 '22 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"":[{.....}"` – Flakes Jan 20 '22 at 03:27
  • Also check objXmlHttpMain.responseText after objXmlHttpMain.send – Flakes Jan 20 '22 at 05:43
  • Does this answer your question? [How to POST JSON Data via HTTP API using VBScript?](https://stackoverflow.com/a/26956711) – user692942 Jan 20 '22 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. – silver Jul 04 '22 at 07:20

0 Answers0