You need to sign in to do that
Don't have an account?

REST API class error
Hi Floks....I got some issue here . please help on this. my issues is
System.HttpResponse[Status=Internal Server Error, StatusCode=500]
This is my code :
public class RESTExample {
public String result{set;get;}
public string grant_type{set;get;}
public string Accesstoken{set;get;}
public string username{set;get;}
public string password{set;get;}
public string client_id{set;get;}
public string client_secret{set;get;}
public string getAccesstoken(){
String reqbody ='grant_type='+password+'&client_id='+client_id+'&client_secret='+client_Secret+'&username='+username+'&password='+password;
Http p= new Http ();
HttpRequest req= new HttpRequest ();
req.setEndpoint('https://sandbox-us-api.experian.com/oauth2/v1/token');
req.setMethod('POST');
req.setBody(reqbody);
system.debug('@@@@the reponse value is ###'+req.getbody());
req.setHeader('Content-Type','application/json;charset=UTF-8');
req.setHeader('accept','application/json');
try{
HttpResponse res = p.send(req);
system.debug('###the reponse value is@@@ '+res.getbody());
//system.debug('#### the value is %%%%%'+res);
// Map<String, String> results = (Map<String, String>) JSON.deserializeUntyped(res.getBody());
// system.debug('@@@Access token value&&&'+ result);
String accessToken ;
System.JSONParser parser=JSON.createParser(result);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME))
{
String fieldName = parser.getText();
parser.nextToken();
System.debug('fieldName'+fieldName);
if (fieldName == 'access_token')
{
accessToken = parser.getText();
}
}
}
}
catch (Exception e){
}
return accessToken;
}
}
System.HttpResponse[Status=Internal Server Error, StatusCode=500]
This is my code :
public class RESTExample {
public String result{set;get;}
public string grant_type{set;get;}
public string Accesstoken{set;get;}
public string username{set;get;}
public string password{set;get;}
public string client_id{set;get;}
public string client_secret{set;get;}
public string getAccesstoken(){
String reqbody ='grant_type='+password+'&client_id='+client_id+'&client_secret='+client_Secret+'&username='+username+'&password='+password;
Http p= new Http ();
HttpRequest req= new HttpRequest ();
req.setEndpoint('https://sandbox-us-api.experian.com/oauth2/v1/token');
req.setMethod('POST');
req.setBody(reqbody);
system.debug('@@@@the reponse value is ###'+req.getbody());
req.setHeader('Content-Type','application/json;charset=UTF-8');
req.setHeader('accept','application/json');
try{
HttpResponse res = p.send(req);
system.debug('###the reponse value is@@@ '+res.getbody());
//system.debug('#### the value is %%%%%'+res);
// Map<String, String> results = (Map<String, String>) JSON.deserializeUntyped(res.getBody());
// system.debug('@@@Access token value&&&'+ result);
String accessToken ;
System.JSONParser parser=JSON.createParser(result);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME))
{
String fieldName = parser.getText();
parser.nextToken();
System.debug('fieldName'+fieldName);
if (fieldName == 'access_token')
{
accessToken = parser.getText();
}
}
}
}
catch (Exception e){
}
return accessToken;
}
}