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

Rest Api System.HttpResponse[Status=Unauthorized, StatusCode=401]
public with sharing class RestClass {
public void RestClass(){
HttpRequest req = new HttpRequest();
req.setEndpoint('https:/*********/services/apexrest/v1/showAccount/');
req.setMethod('GET');
// Specify the required user name and password to access the endpoint
// As well as the header and header information
String username = '*******';
String password = '******';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
// Create a new http object to send the request object
// A response object is generated as a result of the request
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}
}
I am getting Unauthorised Error ..
I have added this to Remote site settings but cannot go through the athentication ..
Any suggestions ...
This below peice helped me to get acess once i got the JSON response parsed to get Access Token ::
String requestUrl = '/services/apexrest/v1/showAccount/';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(instance_Url+''+requestUrl);
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + accessToken);
HTTPResponse res = http.send(req);
String output = res.getBody();
All Answers
This below peice helped me to get acess once i got the JSON response parsed to get Access Token ::
String requestUrl = '/services/apexrest/v1/showAccount/';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(instance_Url+''+requestUrl);
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + accessToken);
HTTPResponse res = http.send(req);
String output = res.getBody();
thanks
Jason