Error while requesting access and refresh token (404)

oauth

#1

Hi,

I’m writing a small java script which will get some reports about email campaigns.

I have a problem when I want to get an access and refresh token using a code (obtained from https://app.hubspot.com/oauth/authorize?client_id=xxxxx&redirect_uri=https://iDontNeetThis.com&scope=reports)

I’m setting a HTTP Post to url https://app.hubspot.com/oauth/v1/token/
using the params

  • grant_type
  • client_id
  • client_secret
  • redirect_uri
  • code

I get following error:

An error occurred while processing your request.
Reference #25.67d81002.1504592913.1b080d23

This is the simplified java code I’m using to reproduce this error:

public class Test {

    private static final String BASE_URL = "https://app.hubspot.com/";

    public static void main(String[] args) throws IOException {
        String code = "abcdef12-3456-7890-abcd-ef1234567890";
        String clientID = "abcdef12-3456-7890-abcd-ef1234567890";
        String clientSecret = "abcdef12-3456-7890-abcd-ef1234567890";
        String url = BASE_URL + "oauth/v1/token/";

        HttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(5);
        urlParameters.add(new BasicNameValuePair("grant_type", "authorization_code"));
        urlParameters.add(new BasicNameValuePair("client_id", clientID));
        urlParameters.add(new BasicNameValuePair("client_secret", clientSecret));
        urlParameters.add(new BasicNameValuePair("redirect_uri", "http://iDontNeedThis.com"));
        urlParameters.add(new BasicNameValuePair("code", code));
        post.setEntity(new UrlEncodedFormEntity(urlParameters));

        System.out.println("post: " + post);
        HttpEntity entity = post.getEntity();
        InputStream content = entity.getContent();

        BufferedReader postReader = new BufferedReader(new InputStreamReader(content));
        StringBuffer str = new StringBuffer();
        String lineStr;

        while ((lineStr = postReader.readLine()) != null){
            str.append(lineStr);
        }

        System.out.println(str);

        HttpResponse response = client.execute(post);
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + post.getEntity());
        System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
        BufferedReader responseReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuilder result = new StringBuilder();
        String line;

        while ((line = responseReader.readLine()) != null) {
            result.append(line);
        }

        System.out.println(result.toString());
    }
}

Unfortunately I cannot find any help for error handling in the documentation, so I want to ask if someone of you can help me.

Thanks,
Felix


#2

@Felix Can you post the response from the HubSpot server?

(edit)Actually are you posting to API.hubspot… or APP.hubspot… you might have entered in the wrong url.


#3

Hello pmanca,

yes it was this one character in my code what is wrong. I didn’t realize this in the long request.

With the url

 https://api.hubspot.com/

it works perfectly.

Thank you :smiley:
Felix