APIs & Integrations

andrew_salman
Participant

The redirect_uri does not match the client registered redirect_uri - what is it?

Im trying to make my first app to get webhooks and getting this message when im trying to integrate my app: "The redirect_uri does not match the client registered redirect_uri. Please contact the integrator". My redirect uri now is https://www.example.com/
Please tell me whats Im doing wrong?

0 Upvotes
4 Replies 4
cbarley
HubSpot Alumni
HubSpot Alumni

The redirect_uri does not match the client registered redirect_uri - what is it?

Hi @andrew_salman , 

The redirect URI you specify when initiating the Oauth connection must exactly match the redirect URI you included in the request to get access/refresh tokens. Using the example from the docs, if you initiate the connection with this URL:

https://app.hubspot.com/oauth/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&scope=contact...

You have to include the exact redirect URI in your request to get access/refresh tokens:

https://api.hubapi.com/oauth/v1/token Headers: Content-Type: application/x-www-form-urlencoded;charset=utf-8 Data: grant_type=authorization_code&client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&client_secret=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy&redirect_uri=https://www.example.com/&code=zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz

 

If you’ve done that and you’re still seeing the error, make sure to check if you have a trailing / at the end, this can cause problems. If you continue to see the error, can you send me the URL you’re using to initiate the connection, as well as the full request you’re sending to get access/refresh tokens (sans code/client secret/etc.)? 

DCrowe
Member

The redirect_uri does not match the client registered redirect_uri - what is it?

I am having a similar problem. My redirect uri was a http://localhost:3000/oauth-callback. I was able to deploy it live on heroku but now I cant. I also can't make it a https://. I have tried using the heroku app as a redirect but that doesn't do the trick either.

DRG
Participant

The redirect_uri does not match the client registered redirect_uri - what is it?

DCrowe, did you ever find a workaround for this?
I'm having a similar problem.
I believe it is because Heroku constantly change the PORT being used and I don't think there is anyway to avoid this.

Danny.

0 Upvotes
andrew_salman
Participant

The redirect_uri does not match the client registered redirect_uri - what is it?

Hellow cbarley
Thank you for reply.
Im receiving the code on my side and Im trying to use 3 conthructions on php:
1) 

$header = "Content-Type: application/x-www-form-urlencoded;charset=utf-8 Data: grant_type=authorization_code&client_id=".HUBSPOT_CLIENT_ID."&client_secret=".HUBSPOT_CLIENT_SECRET."&redirect_uri=" . urlencode(SITE_API_URL . "/hubspot/") . "&code=".$_REQUEST['code'];

 

$curl = curl_init();

curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,'https://api.hubapi.com/oauth/v1/token');
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($curl,CURLOPT_HTTPHEADER,array($header));
curl_setopt($curl,CURLOPT_HEADER,false);
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result,true);


This construction returns nothing

2)

$header = "Content-Type: application/x-www-form-urlencoded;charset=utf-8 Data: grant_type=authorization_code&client_id=".HUBSPOT_CLIENT_ID."&client_secret=".HUBSPOT_CLIENT_SECRET."&redirect_uri=" . urlencode(SITE_API_URL . "/hubspot/") . "&code=".$_REQUEST['code'];

 

$curl = curl_init();

curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,'https://api.hubapi.com/oauth/v1/token');
curl_setopt($curl,CURLOPT_HTTPHEADER,array($header));
curl_setopt($curl,CURLOPT_HEADER,false);
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result,true);

Its GET request and it returns nothing
3)

$data = array(
    'grant_type' => 'authorization_code',
    'client_id' => HUBSPOT_CLIENT_ID,
    'client_secret' => HUBSPOT_CLIENT_SECRET,
    'redirect_uri' => SITE_API_URL . '/hubspot/',
    'code' => $_REQUEST['code']
);

$curl = curl_init();

curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,'https://api.hubapi.com/oauth/v1/token');
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($data));
curl_setopt($curl,CURLOPT_HEADER,false);

$result = curl_exec($curl);
curl_close($curl);
Is a classic POST request with standart HEADERS. It returns 

Array
(
    [status] => BAD_GRANT_TYPE
    [message] => missing or unknown grant type
    [correlationId] => 4e98ae31-8b63-45ec-b7e5-60dd92f7899d
    [requestId] => be2c9bb339f51cc81347070edbe87086
)

 Please tell me what im doing wrong.

0 Upvotes