Using HubSpot with Codenvy

Get started with HubSpot API project using a Codenvy Factory:

Hubspot is marketing content management software. It is a most powerful, tightly integrated and comprehensive marketing software available, putting personalized inbound marketing into the hands of any business. To use the Hubspot Sofware user needs an account at With this software user can create blogs, apps and services provided by HubSpot. In this tutorial we are going to use the blog Service supported by Hubspot.som, create some blog posts, add some comments and subscribe to blog posts for our testing.

Generally we get the created blog on the web with URL provided by Hubspot. For accessing the information about our Blog or services or Email Subscriptions.we can make use of the Hubspot API’s which is available as REST API. For using the HubSpot API one needs to register at After registering at the Hubspot user will get the API key to access the HubSpot API’s or we can use the Default information provided by the API as shown below.


In this tutorial we are going to use the email REST API which retrieves the subscription information for the demo Account.

Create a Project

Project structure in Codenvy:

Create servlet

First create a servlet to access the REST EMAIL API.

package com.codenvy;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HubSpotServlet extends HttpServlet{

private static final long serialVersionUID = 1L;
private HttpClient client = new DefaultHttpClient();

  protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        StringBuffer sb = null;
        try {
            String getURL = "";

            HttpGet req = new HttpGet(getURL);

            HttpResponse res = client.execute(req);
            HttpEntity entity = res.getEntity();
            String responseString = new BasicResponseHandler().handleResponse(res);
            if (entity != null) {

            sb = new StringBuffer("<br/>Simple GET request to url : "+ getURL +"<br/><br/>");
            sb.append("*** Request headers ***").append("<br/>");
            Header[] requestHeaders = req.getAllHeaders();
            for (Header header : requestHeaders) {

            sb.append("*** Response headers ***").append("<br/>");
            Header[] headers = res.getAllHeaders();
            for (Header header : headers) {

            sb.append("*** Response Body ***").append("<br/>");
            String[] str=responseString.split(",");

           for(String s:str){

        } catch (Exception ex) {
            sb = new StringBuffer(ex.toString());

        request.setAttribute("data", sb.toString());
        RequestDispatcher rd = request.getRequestDispatcher("/success.jsp");
        rd.forward(request, response);

In this servlet we are calling the Rest API of Hubspot for retrieving the Email subscription Information. In response we’ll receive information in JSON Objects as shown below.

Create index.jsp and success.jsp Files

We’ll call the Servlet from a Jsp.

<%    response.sendRedirect("/hubspot");%>

We’ll retrieve the information in success.jsp:

<%=request.getAttribute("data") %>

Create pom.xml File

We need to specify the dependencies in pom.xml as shown below:

<project xmlns="" xmlns:xsi=""