# Error getting refresh token

**URL:** <https://community.hubspot.com/t/error-getting-refresh-token/11648>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [October 10, 2018, 1:58pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648 "2018-10-10T13:58:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [October 10, 2018, 1:58pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648/1 "2018-10-10T13:58:41Z")

</div>

I get the following error when trying to get the refresh token:

---

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [October 10, 2018, 2:05pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648/2 "2018-10-10T14:05:36Z")

</div>

getRefreshToken2.php?code=75c5d215-e95a-4497-9e91xxxxxxxxxxxxxxxx:1 Failed to load [https://api.hubapi.com/oauth/v1/token:](https://api.hubapi.com/oauth/v1/token:) Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://localhost](http://localhost)’ is therefore not allowed access.

---

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [October 10, 2018, 3:09pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648/3 "2018-10-10T15:09:40Z")

</div>

I’m using two different pages. One for the initialization of the app which I then use the returned code as a querystring variable in the url where I try to get the refresh token. That is when I get the error. I read in the instructions for the URI in the JSON post data:

The redirect URI that was used when the user authorized your app. This must exactly match the redirect\_uri used when [intiating the OAuth 2.0 connection](https://developers.hubspot.com/docs/methods/oauth2/initiate-oauth-integration).

This is the call I used from my page getRefreshToken2.php:

r=$.ajax({  
url: “[https://api.hubapi.com/oauth/v1/token](https://api.hubapi.com/oauth/v1/token)”,  
type: “POST”,  
data: {client\_id: “XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”,  
client\_secret: “XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”,  
grant\_type: “authorization\_code”,  
redirect\_uri: “[http://localhost/HubSpot-test/initiate-oauth.php](http://localhost/HubSpot-test/initiate-oauth.php)”,  
code: “XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”},  
headers: “Content-Type: application/x-www-form-urlencoded;charset=utf-8”,  
dataType: “json”,  
});  
r.done(function (result) {  
$result="Access Token: " + result.access\_token + "\nrefresh\_token: " + result.refresh\_token + "\nexpires: " + result.expires;  
resultDiv.html($result);

});  
r.fail(function (xhr, thrownError) {alert(xhr.status);alert(thrownError);console.log(xhr);});

---

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [October 10, 2018, 6:54pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648/4 "2018-10-10T18:54:30Z")

</div>

I also get this error when I try it in MS Edge:

XMLHttpRequest: Network Error 0x80070005, Access is denied.

---

<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:** [October 11, 2018, 12:54pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648/5 "2018-10-11T12:54:41Z")

</div>

Hi @jpaullewer,

That error [most often](https://integrate.hubspot.com/t/cors-angular-6-creating-contact-using-api/12490) appears because the OAuth connection flow does not support CORS AJAX requests, per [this documentation](https://developers.hubspot.com/docs/faq/do-hubspot-apis-support-ajax-request).

The AJAX request must be made to your server, which would then add authentication and make the request to the HubSpot server-side.

---

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [October 11, 2018, 1:07pm UTC](https://community.hubspot.com/t/error-getting-refresh-token/11648/6 "2018-10-11T13:07:51Z")

</div>

Thank you. I had to use another method which I was not familiar with. Learning all about curl today. I’ll close this one out.
