400 Error - missing or unknown auth code


In my Production Rails app I seem to have trouble getting the refresh token I need. When I try to get the Auth code I get back "missing or unknown auth code" Any idea what I might be missing - happy to share more fields if needed. Note, on the redirect uri Im redirecting the page and grabbing the params "code" in the URL. Thanks!

   response = HTTParty.post('https://api.hubapi.com/oauth/v1/token',
  body: {
    grant_type: 'authorization_code',
    client_id: APP_CONFIG['hubspot_client_id'],
    client_secret: APP_CONFIG['hubspot_client_secret'],
    redirect_uri: Rails.application.routes.url_helpers.connect_hubspot_site_url(@site, protocol: 'https'),
  headers: {
    "Content-Type" => "application/x-www-form-urlencoded;charset=utf-8"


 "message"=>"missing or unknown auth code",


Hi @john1214,

Are you making this request after you've redirected and received the authorization code? You need to include the authorization code in your request to get the access/refresh tokens; I don't see the code present in the request body you included above.