Creating a New Hubspot Timeline Event: What Am I Missing?

I am trying trying to create a new event using the Timeline Events API, but I keep getting an error: “You don’t have access to this application.”

I followed all the steps (creating an EventType, defined event properties, and defined template) in the following tutorial: https://developers.hubspot.com/docs/methods/timeline/timeline-overview

Here were my prerequisite steps to use the Timeline Events API.

I created a developer account and set that up.

I created an application.

I got a special code by doing the following things.

First, I created the following URL with my new client ID: https://app.hubspot.com/oauth/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&scope=contacts+timeline&redirect_uri=https://www.mysite.com/

After visiting that link, I was given the option of choosing an account (either the main account or my developer account). I chose my main account (my Enterprise account) since that’s the account that I am building the application to use the Timeline Events for.

After choosing my main account, I was redirected to https://www.mysite.com/?code=9e1a7276-86a0-4494-8a4c-248fa1206091

Then, I used that code to get an access_token from Hubspot. Here’s the PHP code for that. I had to set it up on my server and visit a page to activate it.

$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded;charset=utf-8';

$hubEventUrl  = "https://api.hubapi.com/oauth/v1/token";
$fields = "grant_type=authorization_code";
$fields .= "&client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$fields .= "&client_secret=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$fields .= "&redirect_uri=https://www.mysite.com/";
$fields .= "&code=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$hubEventUrl);
curl_setopt($ch,CURLOPT_POST, 5);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result=curl_exec($ch);
curl_close($ch);

var_dump($result);

die();

Now, for the final step, I am trying to use the access token to create a timeline event for a contact in my main enterprise account. I followed all the steps (creating an EventType, defined event properties, and defined template) in the following tutorial: https://developers.hubspot.com/docs/methods/timeline/timeline-overview

Here’s the PHP code I am using for the final step. If anyone is interested, I have this set up in a PHP function, and it runs when I visit a certain URL.

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$hubEventUrl  = 'https://api.hubapi.com/integrations/v1/179916/timeline/event?hapikey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&userId=xxxxxxx;

$json = '{"id": "101921", "userEmail":"user@outlook.com","email":"user@gmail.com"}';

$fields = "id=101921";
$fields .= "&eventTypeId=279606"; 
$fields .= "&userEmail=user@gmail.com";
$fields .= "&email=user@outlook.com";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$hubEventUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch,CURLOPT_POST, 4);
curl_setopt($ch,CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result=curl_exec($ch);

var_dump($result);

die();

A couple questions about $hubEventUrl. In this tutorial (https://developers.hubspot.com/docs/methods/timeline/create-or-update-event), it says that “You must use an OAuth access token to create an event. API keys are not supported.” However, if I don’t include the hapikey in the $hubEventUrl, I get an error. I assumed I needed to use my developer account’s hapikey, but I noticed my Enterprise account also has a hapikey.
1) Do I use my developer account’s hapikey or my Enterprise account’s hapikey?
2) Also, same question for the userId. Do I use my developer account user’s ID, or my Enterprise account user’s ID? I have tried both, but I get the same error “”You don’t have access to this application.”

Just as a side note, this is a lot of work just to use the Timeline Events API. Is there an easier way?

Thanks, in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *