Link to home
Start Free TrialLog in
Avatar of terrybuck9
terrybuck9

asked on

I need to Integrate Hubspot into my .asp application but don't know how to POST

Hi

I am a total beginner in Hubspot and JSON

My application has a landing page (.asp) where I have gathered all my client details and I now have to update Hubspot.

Looking at their manuals I guess I need to put all my variables in a <script> </script> like below:
<script>
{
  "properties": [
    {
      "property": "email",
      "value": "test@hubspot.com"
    },
    {
      "property": "firstname",
      "value": "HubSpot"
    }
  ]
}
</script>

firstly is this correct?

then I need to do a post with a command like:
Example POST URL:
https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/testingapis@hubspot.com/?hapikey=demo

secondly, how do I do this post in my .asp file to send the data?

Please can you help as I don't know where to start?  as Hubspot don't seem to want to get involved in any integrations.

Thanks Terry
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

have you checked up their online documentation?

http://developers.hubspot.com/docs/methods/contacts/contacts-overview

try click on the sub-menu items and they got posted some examples there (provided in php).

User generated image
do you need to get it done in ASP?
Avatar of terrybuck9
terrybuck9

ASKER

Hi

Yes I have seen this, but I am not a php programmer either.

I can do it in either as long as it can sit on my .asp page.

Your advice would be great.  But I do need to know syntax and where to put it, and how to call it.

Thanks Terry
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America 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
Hi Big Monty

thanks for your help.

I don't get the first bit, as I think I need to "send it server side".  As I have various .asp pages that gather information in forms and land on my last page.

so if I insert my code in my .asp page like this:

<%
PostData = "<
{
  "properties": [
    {
      "property": "email",
      "value": "test@hubspot.com"
    },
    {
      "property": "firstname",
      "value": "HubSpot"
    }
  ]
}
>"
Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST", "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/testingapis@hubspot.com/?hapikey=demo"
ServerXmlHttp.setRequestHeader "Content-Type", "application/json"
ServerXmlHttp.setRequestHeader "Content-Length", Len( PostData )
ServerXmlHttp.send PostData
%>

Please let me know if syntax correct?

then

<%
If ServerXmlHttp.status = 200 Then
    TextResponse = ServerXmlHttp.responseText
    XMLResponse = ServerXmlHttp.responseXML
    StreamResponse = ServerXmlHttp.responseStream
Else
    ' Handle missing response or other errors here
End If

Set ServerXmlHttp = Nothing
%>

then the response will be in StreamResponse if success?

I know this is all basic stuff, but It just hasn't clicked yet.

Thanks Terry
Hi Big Monty

I have been messing and I did this, and I get a 400 response.

<%
 PostData = "<{""properties"": [{""property"": ""email"",""value"": ""test@hubspot.com""},{""property"": ""firstname"",""value"": ""HubSpot""}]}>"
 Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
 ServerXmlHttp.open "POST", "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/terry@hubspot.com/?hapikey=demo"
 ServerXmlHttp.setRequestHeader "Content-Type", "application/json"
 ServerXmlHttp.setRequestHeader "Content-Length", Len( PostData )
 ServerXmlHttp.send PostData
 %>

 

 <%
 If ServerXmlHttp.status = 200 Then
     TextResponse = ServerXmlHttp.responseText
     XMLResponse = ServerXmlHttp.responseXML
     StreamResponse = ServerXmlHttp.responseStream
 Else
     ' Handle missing response or other errors here
     response.Write (ServerXmlHttp.status)
 End If

 Set ServerXmlHttp = Nothing

     response.Write (TextResponse)
 %>
your syntax looks good on your latest post. if you're getting a 400 response, it means that attempt to send the data was good, but failed, either due to a bad URL or there was an access issue. Using the link directly, it came back with no response, so I would work first on getting the right URL in place and trying to access it directly in the browser. once you have that figured it, you should be able to plug it into your page
Hi

Great thanks, sounds like I am on the right track.

I changed data to:
 PostData = "{""properties"": [{""property"": ""email"",""value"": ""test@hubspot.com""},{""property"": ""firstname"",""value"": ""HubSpot""}]}"

taking out the < and >.

now I am getting a 409?

Terry
Hi Big Monty

I think I have cracked it with your help.

I now get a response:

{"vid":4027074,"isNew":true}

Which means it works.

thanks very much, you helped me get off the ground.

Thanks Again

Terry
always validate your JSON (which this is) with an online validator, such as https://jsonformatter.curiousconcept.com/. To do so, simply do:

Response.Write PostData
Response.End

now run the page and you'll get the JSON string. Copy and paste that into the URL above and it'll tell you if it's valid or not.

as for the 409 response, I'm not sure. It's defined as a conflict, but I'm unsure of what that means...
glad i could help :)
Works a treat, used the server side option.

 Thanks Terry