Re: Ability to refresh API token?

Anonymous
Not applicable

Ability to refresh API token?

Hi,

Does Marketo have something similar ot a Access Token Refresh URL? I'm trying to access your API, however, my token expires, and I want a way to automaticaly update my token when it does so.

Thanks!
Tags (1)
8 REPLIES 8
Anonymous
Not applicable

Re: Ability to refresh API token?

You would neee to poll the auth endpoint to automatically generate auth tokens:

Anonymous
Not applicable

Re: Ability to refresh API token?

Can you please point me to the JAVA code to get the security token. The example in the link above has only the RUBY code.
Anonymous
Not applicable

Re: Ability to refresh API token?

@Preeti, I just added Java sample code to get the security token on this documentation page.

http://developers.marketo.com/documentation/rest/authentication/
Anonymous
Not applicable

Re: Ability to refresh API token?

Thank you very much
Anonymous
Not applicable

Re: Ability to refresh API token?

Is there a way to speicifiy (customize) the expiration time for the token?
Anonymous
Not applicable

Re: Ability to refresh API token?

Unfortunately not. The token expires every hour.
Anonymous
Not applicable

Re: Ability to refresh API token?

Thank you very much for the Java example. IT helped me move forward.

I customized it a little bit to get the token, as I was always getting a 406 error.

//////////////////////// ***************** ///////////////////
private String getToken(){
        URL url;
        String token = null;
        String marketoInstance = "https://AAA-BBB-CCC.mktorest.com/identity/oauth/token?grant_type=client_credentials";
        String oauthURL = marketoInstance + "&client_id=" + client_id + "&client_secret=" + client_secret;
        try {
            url = new URL(oauthURL);
            HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();            
            
            if(urlConn!=null){     
                try {         
                    BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));         
                    for (String x = br.readLine(); x != null; x = br.readLine()) {
                        x = x.replace("{", "");
                        x = x.replace("}", "");
                        String[] content = x.split(",");
                        for (String tkn : content) {
                            if(tkn.contains("access_token")){
                                String temp = tkn.split("\":\"")[1];
                                if(temp != null){
                                    token = temp.replace("\"", "");
                                    return token;
                                }
                            }
                        }                    
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return token;
    }
Anonymous
Not applicable

Re: Ability to refresh API token?

I am glad you were able to get it working!