# Showing up login screen, when creating a timeline events for each contact via Java Coding/POSTMAN

**URL:** <https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150>\
**Category:** APIs & Integrations\
**Tags:** contacts, timeline-and-extensions-apis\
**Created:** [November 12, 2019, 5:10am UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150 "2019-11-12T05:10:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahesh1250](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mahesh1250/32/97852_2.png) [@Mahesh1250](https://community.hubspot.com/u/Mahesh1250)\
**Post date:** [November 12, 2019, 5:10am UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/1 "2019-11-12T05:10:32Z")

</div>

Hi Experts,

How can we get value for

“code”

without logging into Hubspot account when we’re hitting the URL from java code or POSTMAN? (where end-user shouldn’t notice any of these actions)

**For example:** If I hit the below URL in the browser (Private mode)

[https://app.hubspot.com/oauth/\<\<Acc-ID\>\>/authorize?client\_id=\<\<client\_id\>\>&redirect\_uri=\<\<URI\>\>&scope=contacts+timeline+oauth+integration-sync+tickets+e-commerce](https://community.hubspot.com/)

It’s asking for login to Hubspot and then redirecting to

\<\<redirect\_uri\>\>

with query param

“code”.

\<\<redirect\_uri\>\>/?code=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx

How can I authenticate via java coding to get the value for query param

“code”

or do we have any other way of implementation for creating Timeline events for each contact via Java code?

Please let me know if I need to pass any extra params to authorize automatically.

Please see attached screenshots for reference.

 ![Screen Shot 2019-11-12 at 4.05.12 pm.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/3/329e77565af0c3bdcf428e7b8faf01decafaa3e6.png)  
Image1  
 ![Screen Shot 2019-11-12 at 4.03.15 pm.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/b/6b0976c3b4d91e53cc5930fab39823b48ed401b2.jpeg)  
Image2

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [November 18, 2019, 9:39am UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/2 "2019-11-18T09:39:40Z")

</div>

Hii @Mahesh1250

It’s the standard process which is followed in an oauth 2.0.

When we initiate the oauth with Client ID and Client Secret, we need to login to HubSpot and select the specific portal which needs to be connected with the APP. It can be a case that under a single email account, we can have multiple portals registered. So here it becomes necessary to select the account/portal.

After a portal being selected, it asks for access to following scopes that APP uses and connects the APP with account. Thenafter, the flow get back to URL mentioned under **redirect\_uri** with query param **code** which helps in getting **access and refresh token.**

Thanks.

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [November 18, 2019, 6:42pm UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/3 "2019-11-18T18:42:11Z")

</div>

Thanks as always, @himanshurauthan!

Said differently, @Mahesh1250, HubSpot only uses OAuth’s [Authorization Code Flow](https://auth0.com/docs/flows/concepts/auth-code), which _must_ involve user action the first time an app is connected. There is no programmatic workaround here — a logged-in user must approve the scopes the app is requesting.

Once this is done, though, and your app retrieves the `code` from the `redirect_uri` and uses it to [get access and refresh tokens](https://developers.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens), you don’t need to involve users going forward unless the app becomes disconnected. Your app can programmatically refresh the access tokens when they expire for use in creating timeline events.

---

<div class="post-metadata">

**Author:** ![Mahesh1250](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mahesh1250/32/97852_2.png) [@Mahesh1250](https://community.hubspot.com/u/Mahesh1250)\
**Post date:** [November 20, 2019, 4:01am UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/4 "2019-11-20T04:01:00Z")

</div>

Thanks, @himanshurauthan & @IsaacTakushi for the response.

How we will handle the requirement like

- For every successful contact login into a Hybris based eCommerce website, we need to create a timeline event for that contact to know how many times he logged-in in the last 4 weeks.

Note: This eCommerce user doesn’t have an account with HubSpot (not like a Google/Facebook) to enter credentials when HubSpot login screen pops up.

If there are multiple portals in one Hubspot account, we can send link like below to pick the exact one ( **6595917** )

[https://app.hubspot.com/oauth/](https://app.hubspot.com/oauth/authorize?client_id=44954df5-d930-4cb6-8c75-4a2a0935fd43&redirect_uri=http://localhost:9001/portal/b2b&scope=contacts%20automation%20timeline%20oauth%20forms%20hubdb%20integration-sync%20e-commerce)**[6595917](https://app.hubspot.com/oauth/6595917/authorize?client_id=44954df5-d930-4cb6-8c75-4a2a0935fd43&redirect_uri=https%3A%2F%2Fonlinedev.device.com.au%2F&scope=contacts+timeline+oauth+integration-sync+tickets+e-commerce)**/[authorize?client\_id=44954df5-xxxx-xxxx-xxxx-4a2a09xxxx43&redirect\_uri=http://localhost:9001/xxxx/xxx&scope=contacts%20automation%20timeline%20oauth%20forms%20hubdb%20integration-sync%20e-commerce](https://app.hubspot.com/oauth/authorize?client_id=44954df5-d930-4cb6-8c75-4a2a0935fd43&redirect_uri=http://localhost:9001/portal/b2b&scope=contacts%20automation%20timeline%20oauth%20forms%20hubdb%20integration-sync%20e-commerce)

If we click on the above URL, it’ll ask me to log in.

**Question 1:** can I send credentials in any way to automate the function. or can I use any other grant type(instead of authorization\_code) to get an access token to create timeline events?

Please suggest me the best approach to achieve this requirement.

Thanks in advance!

Thanks,

Mahesh.S

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [November 20, 2019, 10:24pm UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/5 "2019-11-20T22:24:47Z")

</div>

Hi, @Mahesh1250.

Your [HubSpot app](https://developers.hubspot.com/docs/faq/how-do-i-create-an-app-in-hubspot) only exists between the Hybris back end and your HubSpot account. End users like those logging into a Hybris-based ecommerce site will never interact with the HubSpot APIs, just with your front end.

Said differently, individual users do not need OAuth tokens. Instead, the Hybris _back end_ needs one valid OAuth token per account so that it can create timeline events based on Hybris login events.  
To kick off the process which gives your back end OAuth tokens, one of the users in your own HubSpot account (e.g. your test account, **6595917** ) must navigate to your app’s authorization URL and approve the integration.  
Once this is completed, your back end service can pick up the `code` value appended to the `redirect_uri` and make a request to [this endpoint](https://developers.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens). If your request is valid, you will receive your first access and refresh tokens.  
From this point, no user interaction is required as long as your app remains connected to account **6595917**. Your back end code should refresh the access tokens whenever you need to send information from Hybris into your HubSpot account.

---

<div class="post-metadata">

**Author:** ![Mahesh1250](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mahesh1250/32/97852_2.png) [@Mahesh1250](https://community.hubspot.com/u/Mahesh1250)\
**Post date:** [November 21, 2019, 4:55am UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/6 "2019-11-21T04:55:29Z")

</div>

Thank you very much @IsaacTakushi for the solution  
 ![16x16_smiley-very-happy.png.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/a/a83ec960612094a57cfb392e21c202c8e77b967c.png)

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [November 21, 2019, 1:14pm UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/7 "2019-11-21T13:14:48Z")

</div>

I’m glad I could help clarify, @Mahesh1250!

I see your testing app is now connected to account **6595917**! Let either @himanshurauthan or me know if you’re having issues refreshing access tokens. It can be tricky at first.

---

<div class="post-metadata">

**Author:** ![Mahesh1250](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mahesh1250/32/97852_2.png) [@Mahesh1250](https://community.hubspot.com/u/Mahesh1250)\
**Post date:** [November 22, 2019, 6:24am UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/8 "2019-11-22T06:24:39Z")

</div>

Hi @IsaacTakushi,

Thanks for your support! 🙂

After seeing your response, I confirmed that the first time we need to authenticate the app to get the **code** and by using this code we’ll get **access\_token** & **Refresh\_token**.

1. **Access\_token** will expire every **6 hours** , so we need to catch the invalid token exception and need to create new **access\_token** by using **refresh\_token**. So in this way, we don’t need to repeat step 1 (i.e.authenticate the app to get the **code** ) which is good.

**Question :**

- Is there **any expiration for refresh\_token**? If yes, how we need to handle this case in production environments?

Thanks,

Mahesh.S

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [November 22, 2019, 2:59pm UTC](https://community.hubspot.com/t/showing-up-login-screen-when-creating-a-timeline-events-for-each-contact-via-java-coding-postman/17150/9 "2019-11-22T14:59:12Z")

</div>

Hey, @Mahesh1250.

Happy to help  
 ![16x16_smiley-very-happy.png.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/a/a83ec960612094a57cfb392e21c202c8e77b967c.png)

No, `refresh_token` values do not expire, so you can request a new `access_token` at any time.

In fact, if your app is not making calls, you can even let the access token expire and refresh it only when you need it.
