AnsweredAssumed Answered

v10 API always returns invalid grant when requesting refresh

Question asked by Noah Hall on Oct 1, 2015
Latest reply on Oct 12, 2015 by Noah Hall
after about 5minutes I am always returned an invalid grant when using the v10 api
What am I doing wrong?

function get_sugar_oauth($refresh = false){    global $OAUTH;
    

    if (empty($refresh)){
        $grant_type = 'password';
        $oauth_args = array(
            "grant_type" => $grant_type,
            "client_id" => $GLOBALS['SUGAR_ID'],
            "client_secret" => $GLOBALS['SUGAR_SECRET'],
            "platform" => $GLOBALS['SUGAR_PLATFORM'],
            "username" => SUGAR_USERNAME,
            "password" => SUGAR_PW
        );

        try{
            $OAUTH = call_sugar(SUGAR_OAUTH_URL, '', 'POST', $oauth_args);
            return $OAUTH;
        }catch (Exception $e){
            $GLOBALS['SCRIPT_ERRORS']['get_sugar_oauth'][] = array(date('Y-m-d g:i a',time()), __LINE__,$e);
            global $sync_this;
            print_results_then_die($sync_this);
        }
    }else{
        $grant_type = 'refresh_token';
        $oauth_args = array(
            "grant_type" => $grant_type,
            "refresh_token" => $OAUTH->refresh_token,
            "client_id" => $GLOBALS['SUGAR_ID'],
            "client_secret" => $GLOBALS['SUGAR_SECRET'],
        );

        $REFRESH = call_sugar(SUGAR_OAUTH_URL,$OAUTH->access_token,'POST', $oauth_args);
        $OAUTH = $REFRESH;
    }

    return $OAUTH;
}

Outcomes