# Timeline API - using Ajax

**URL:** <https://community.hubspot.com/t/timeline-api-using-ajax/11276>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [October 4, 2018, 11:19am UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276 "2018-10-04T11:19:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![socialpilgrim](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/socialpilgrim/32/44503_2.png) [@socialpilgrim](https://community.hubspot.com/u/socialpilgrim)\
**Post date:** [October 4, 2018, 11:19am UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/1 "2018-10-04T11:19:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cbarley/32/82559_2.png) [@cbarley](https://community.hubspot.com/u/cbarley)\
**Post date:** [October 4, 2018, 3:38pm UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/2 "2018-10-04T15:38:05Z")

</div>

Hi [@rajputsushil](https://community.hubspot.com/u/rajputsushil), The issue here is that timeline events cannot be created using ajax. Please see this article: [Accounts Dashboard | HubSpot](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](https://developers.hubspot.com/), 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: [Screenshot by Lightshot](http://prntscr.com/l26nlr)

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

---

<div class="post-metadata">

**Author:** ![socialpilgrim](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/socialpilgrim/32/44503_2.png) [@socialpilgrim](https://community.hubspot.com/u/socialpilgrim)\
**Post date:** [October 5, 2018, 6:33am UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/3 "2018-10-05T06:33:37Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![cbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cbarley/32/82559_2.png) [@cbarley](https://community.hubspot.com/u/cbarley)\
**Post date:** [October 5, 2018, 3:46pm UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/4 "2018-10-05T15:46:26Z")

</div>

Hi [@rajputsushil](https://community.hubspot.com/u/rajputsushil), do you have a test account? [Accounts Dashboard | HubSpot](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](https://developers.hubspot.com/docs/methods/oauth2/oauth2-overview) before you can submit a Timeline Event. Make sure you read the Prerequisites section in [this article](https://developers.hubspot.com/docs/methods/timeline/timeline-overview) before you jump into creating timeline events

---

<div class="post-metadata">

**Author:** ![socialpilgrim](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/socialpilgrim/32/44503_2.png) [@socialpilgrim](https://community.hubspot.com/u/socialpilgrim)\
**Post date:** [October 9, 2018, 12:59pm UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/5 "2018-10-09T12:59:58Z")

</div>

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/](https://api.hubapi.com/integrations/v1/)\<\<\>\>/timeline/event?hapikey=”\<\<\>&userId=\<\<\>\>";

```auto
$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

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

```

// I havent got Bearer token so I am using access\_token below

```auto
	$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](mailto:support@xxxxx.com)”.

Not sure what is I am missing here.

You can test code here →   
[https://290px.com/app/oauth.php](https://290px.com/app/oauth.php), provide any hubid…

---

<div class="post-metadata">

**Author:** ![cbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cbarley/32/82559_2.png) [@cbarley](https://community.hubspot.com/u/cbarley)\
**Post date:** [October 9, 2018, 2:02pm UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/6 "2018-10-09T14:02:08Z")

</div>

Hi [@rajputsushil](https://community.hubspot.com/u/rajputsushil), that doesn’t look like the correct URL. You should be making a PUT request to

```auto
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: [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/methods/timeline/create-or-update-event)

---

<div class="post-metadata">

**Author:** ![socialpilgrim](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/socialpilgrim/32/44503_2.png) [@socialpilgrim](https://community.hubspot.com/u/socialpilgrim)\
**Post date:** [October 9, 2018, 6:40pm UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/7 "2018-10-09T18:40:42Z")

</div>

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](https://290px.com/app/oauth.php)

---

<div class="post-metadata">

**Author:** ![socialpilgrim](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/socialpilgrim/32/44503_2.png) [@socialpilgrim](https://community.hubspot.com/u/socialpilgrim)\
**Post date:** [October 10, 2018, 2:04pm UTC](https://community.hubspot.com/t/timeline-api-using-ajax/11276/8 "2018-10-10T14:04:27Z")

</div>

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](https://mywebinarsystem/webinar/%7Bsessionid%7D)**
