Timeline API - using Ajax


#1

Hey I am trying to add timeline on form submit using ajax request thru javascript,

Flow ->

  1. Form submit ( redirects to another form)
  2. capture user details
  3. call timeline api event to create timeline ( using javascript)
  4. redirect to external url ( using javascript)

at step 3 I am getting below error

{"status":"error","message":"You don't have access to this application.","correlationId":"46861cf4-64fa-425a-8a26-89aaffe78622","requestId":"47bed49c290f7553acdbc61c28c02956"}

How I can check I where I am doing wrong like access related details ?

Already checked with hubspot guys, but seems no issue on permission end


#3

Hi @rajputsushil, The issue here is that timeline events cannot be created using ajax. Please see this article: https://developers.hubspot.com/docs/faq/do-hubspot-apis-support-ajax-request. In order to create timeline events via the timeline api, you'll need to create a developer portal, and then create an App via OAuth inside your developer portal.

That said, when a contact submits a form there should be a section on that contact's timeline related to a submission, like this: http://prntscr.com/l26nlr

Why are you looking to create a timeline event after a form submission?


#4

Hi Connor,
Thanks for the reply .... I could see this is new for me, I had developer account and I was able to use api to get access to event type.

But not sure how I use this to create timline in contact .... means how to link both dev and other(non-developer) account, since timeline is not in other(non-developer) account.

I tried (non-developer) account appid, myuser id and my hapikey but no access...

What is the way forward ?


#5

Hi @rajputsushil, do you have a test account? https://developers.hubspot.com/docs/faq/how-do-i-create-a-test-portal. The root of the issue you're seeing is that Developer Portals and normal/test portals is that Developer Portals do not and cannot have any of those tools in them. To test how an application would work with a live portal, we'd either use a live portal if you have one, or create a test portal as I stated above.

If you create a test portal, you should be able to go into that and either create some contacts to test the timeline API on, or create a timeline event on an existing contact if you have them. You'll need the grant the application authorization to that test portal by going through the OAuth flow before you can submit a Timeline Event. Make sure you read the Prerequisites section in this article before you jump into creating timeline events


#6

Hi connor .... thanks for the reply, I am able to test with account and dev account and getting access_token

$hubEventUrl. = "https://api.hubapi.com/integrations/v1/<<>>/timeline/event?hapikey="<<>&userId=<<>>";

$re = $_SESSION["result"];

// here portalId= non dev account id
//eventTypeId = already created in dev account with 2 properties, emailid, sessionid
//email[support@xxxxx.com] = already present in non dev account as contact

	$json = '{"id": "'.$_SESSION["portalId"].'", "eventTypeId":"380358","email":"support@xxxxx.com"}';

// I havent got Bearer token so I am using access_token below

	$headers = array();
	$headers[] = "Content-Type: application/json";
	$headers[] = "Authorization: Bearer ".$re["access_token"];	
			
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $hubEventUrl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
	curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
	curl_setopt($ch, CURLOPT_POST, 3);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

	$xjson = curl_exec($ch);

On execution if this I am not getting any response and not even Timeline is created for contact "support@xxxxx.com".

Not sure what is I am missing here.

You can test code here ->
https://290px.com/app/oauth.php, provide any hubid....


#7

Hi @rajputsushil, that doesn't look like the correct URL. You should be making a PUT request to

https://api.hubapi.com/integrations/v1/<<applicationId>>/timeline/event

Hapikey shouldn't be present to create a timeline event. you'd only need the developer portal's hapikey if you were making a GET request to see all timeline events that you'd created. The specifics of creating a timeline event are here: https://developers.hubspot.com/docs/methods/timeline/create-or-update-event


#8

If I try without hapikey .... I get below error

{"status":"error","message":"Any of the listed authentication credentials are missing","correlationId"

and If I use hapikey, userid I dont get this error..

I tried 3 combination ... in place of appid ...

  1. I tried both dev
  2. and non-dev account and error is same.
  3. Even tried removing "Bearer" from Authorization header

but error is same .

Is there anything to do with event created manually in dev account ?

You can response here
https://290px.com/app/oauth.php


#9

Hey Connor .... thanks for the support, I am able to create event now.

new test had Demo.ja.sg event
Registered for admin@tzone.com