I made scheduled class to get access token and save it to the custom object.. I set the scheduled jobs, using the UI (apex class > schedule apex), to run the class everyday.. but its not firing..
here`s my class
global class Purecloud_Connector implements Schedulable{
//public static String CRON_EXP = '0 0 1/1 * *';
global void execute(SchedulableContext ctx){
String clientId = '[CLIENT ID]';
String clientSecret = '[CLIENT SECRET]';
String connId = 'a1cO0000001UZ83IAG';
String accessToken;
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(clientId + ':' + clientSecret)));
req.setHeader('Host','[HOST]');
req.setHeader('content-type', 'application/x-www-form-urlencoded');
req.setEndpoint('[END POINT]');
req.setBody('grant_type=client_credentials');
Http http = new Http();
try{
HTTPResponse res = http.send(req);
System.debug('res:' + res);
System.debug('body:' + res.getBody());
JSONParser parser;
parser = JSON.createParser(res.getBody());
integer x = 0;
while (parser.nextToken() != null) {
x++;
system.debug('countLoop:' + x);
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'access_token')){
parser.nextToken();
accessToken = parser.getText();
}
Purecloud_Connector__c conn = new Purecloud_Connector__c();
conn.id = connId;
conn.Access_Token__c = accessToken;
update conn;
}
} catch(System.CalloutException e){
System.debug('exception:' + e);
// do something useful here
}
}
}