# Access token return 500 Internal Server Error

**URL:** <https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [July 18, 2019, 1:21pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382 "2019-07-18T13:21:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![KingswaySoft](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kingswaysoft/32/27811_2.png) [@KingswaySoft](https://community.hubspot.com/u/KingswaySoft)\
**Post date:** [July 18, 2019, 1:21pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/1 "2019-07-18T13:21:24Z")

</div>

When connecting to a certain HubSpot account, after getting the authorization code, the get access token fails with 500 Internal Server Error.

{“status”:“error”,“message”:“internal error”,“correlationId”:“22fc323d-85b7-429c-a15a-2bb4d58bdaeb”,“requestId”:“ff01a1df8ca91be60b250d9450afc1a4”}

Our app id: 28750

Can you please take a look and let us know why it is failing?

---

<div class="post-metadata">

**Author:** ![robertainslie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/robertainslie/32/1875_2.png) [@robertainslie](https://community.hubspot.com/u/robertainslie)\
**Post date:** [July 19, 2019, 12:31pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/2 "2019-07-19T12:31:10Z")

</div>

Hi @KingswaySoft -

To help out here, can you give a bit more detail about the steps of the process? Specifically, if you’re at the stage of swapping the

code

for an access token, can you provide the following:

- full URL of HTTP request

- Method

- Headers

- body (be sure to redact your `

Less necessary, but you can provide your code snippet too.

---

<div class="post-metadata">

**Author:** ![KingswaySoft](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kingswaysoft/32/27811_2.png) [@KingswaySoft](https://community.hubspot.com/u/KingswaySoft)\
**Post date:** [July 19, 2019, 1:29pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/3 "2019-07-19T13:29:15Z")

</div>

Hi @robertainslie , thank you for getting back to us.

Please find the request below:

POST [https://api.hubapi.com/oauth/v1/token](https://api.hubapi.com/oauth/v1/token) HTTP/1.1  
Accept: application/json  
Content-Type: application/x-www-form-urlencoded  
Host: [api.hubapi.com](http://api.hubapi.com)  
Content-Length: 220  
Accept-Encoding: gzip, deflate  
Connection: Keep-Alive

grant\_type=authorization\_code&client\_id=551f82b2-2fe6-11e5-9def-3ff296bb2e59&client\_secret=555555&redirect\_uri=https%3a%2f%[2fwww.kingswaysoft.com](http://2fwww.kingswaysoft.com)%2f&code=f1d119db-2161-4640-829f-7d0b8388e0fe

---

<div class="post-metadata">

**Author:** ![robertainslie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/robertainslie/32/1875_2.png) [@robertainslie](https://community.hubspot.com/u/robertainslie)\
**Post date:** [July 19, 2019, 8:17pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/4 "2019-07-19T20:17:00Z")

</div>

Hi @KingswaySoft ,

The only thing that jumps out to me is maybe the URL encoding of your redirect\_uri. Can you double check that the URL isn’t being double encoded?

Additionally, can you test this exact request in Postman, outside of the context of your code? Here’s a Postman collection to edit - [https://www.getpostman.com/collections/a231c29e2ec393f87b2a](https://www.getpostman.com/collections/a231c29e2ec393f87b2a)

You can import that to postman via File \> Import \> Import from URL. Then, edit the request to include your client id and client secret. Go through the first step of the flow in your browser to get a new code parameter, and then copy/paste into the Postman collection and Post. Let me know the results.

---

<div class="post-metadata">

**Author:** ![KingswaySoft](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kingswaysoft/32/27811_2.png) [@KingswaySoft](https://community.hubspot.com/u/KingswaySoft)\
**Post date:** [July 19, 2019, 9:30pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/5 "2019-07-19T21:30:23Z")

</div>

Hi @robertainslie , I’m sure the redirect\_uri is not double encoded.

I have just tried in Postman and got the same 500 error result.

This error only happens to a particular HubSpot instance, the portalId is 163004 if it helps for you investigation.

---

<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:** [July 22, 2019, 1:53pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/6 "2019-07-22T13:53:36Z")

</div>

Hi, @KingswaySoft.

I’ll be taking this over for @robertainslie. I’ve just sent you a direct message.

---

<div class="post-metadata">

**Author:** ![KingswaySoft](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kingswaysoft/32/27811_2.png) [@KingswaySoft](https://community.hubspot.com/u/KingswaySoft)\
**Post date:** [July 23, 2019, 5:13pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/7 "2019-07-23T17:13:54Z")

</div>

Hi @IsaacTakushi , I responded to your direct message yesterday, can you please check and update us if you found anything?

---

<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:** [July 24, 2019, 12:18am UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/8 "2019-07-24T00:18:50Z")

</div>

Hi, @KingswaySoft.

Thanks for your patience.

I’ve run nearly 40 tests today with your auth URL, different accounts, and different users and have an update!

I can consistently reproduce `500` errors from [this endpoint](https://developers.hubspot.com/docs/methods/oauth2/get-access-and-refresh-tokens) after authenticating your app with a **Super Admin** who has **Sales Professional** or **Enterprise** access — the same permission set as the user in account **163004**.

Once a user with both the **Super Admin** and **Sales Professional/Enterprise** roles triggers a `500` error, they are unable to connect the app under any circumstances. Revoking the roles and even changing the auth URL have no effect — the endpoint will continue to return `500` errors for that user.

Curiously, other combinations of roles work perfectly. An **Admin** with **Sales Professional/Enterprise** access can connect and disconnect the app any time, as can a **Super Admin** with no **Sales Professional/Enterprise** seat.

I can continue to dig into this issue. In the meantime, could you have a different user with the appropriate permissions in account **163004** connect your app? (Depending on your client’s needs, either of the combinations above will work.)

Please let me know if I can clarify further.

---

<div class="post-metadata">

**Author:** ![KingswaySoft](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kingswaysoft/32/27811_2.png) [@KingswaySoft](https://community.hubspot.com/u/KingswaySoft)\
**Post date:** [July 24, 2019, 2:10pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/9 "2019-07-24T14:10:13Z")

</div>

Hi @IsaacTakushi , thank you for the update, glad to hear you can reproduce the issue.

We have suggested our client to try with a different user for now, please keep us posted if you find anything else. We are eager to know the root cause of this issue.

---

<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:** [December 10, 2019, 2:09pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/10 "2019-12-10T14:09:23Z")

</div>

Hi, @KingswaySoft.

So sorry for not being in touch.

This should now be _fully_ resolved. We found that when all possible [scopes](https://developers.hubspot.com/docs/methods/oauth2/initiate-oauth-integration) were requested _and_ granted, it caused a timeout that triggered the `500` errors. This issue was rare because it only occurred when users had access to tools like transactional email, which most HubSpot customers do not have.

One of my other colleagues will notify the owners in account **163004** directly.

Thank you for your patience throughout this long process.

---

<div class="post-metadata">

**Author:** ![KingswaySoft](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kingswaysoft/32/27811_2.png) [@KingswaySoft](https://community.hubspot.com/u/KingswaySoft)\
**Post date:** [December 10, 2019, 8:59pm UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/11 "2019-12-10T20:59:44Z")

</div>

Thanks @IsaacTakushi for the update. Glad to hear the issue is resolved.

---

<div class="post-metadata">

**Author:** ![dannio](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dannio/32/95715_2.png) [@dannio](https://community.hubspot.com/u/dannio)\
**Post date:** [March 17, 2022, 8:43am UTC](https://community.hubspot.com/t/access-token-return-500-internal-server-error/15382/12 "2022-03-17T08:43:30Z")

</div>

Hi @IsaacTakushi . I’m having the same issue when trying to get an access token for a test app I’m trying on a dev account. What was the solution in the end?

Sorry, ignore me. Was being dumb and found a typo.
