You need to sign in to do that
Don't have an account?
![ManojKumar Muthu ManojKumar Muthu](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
System.HttpResponse[Status=Unauthorized, StatusCode=401
I got stuck here, can someone help to slove this error,
below my code,
Trigger:
trigger Level2Update on Account_Case_Escalation__c (after update) {
for(Account_Case_Escalation__c ACE: trigger.new)
{
util.callwebservice(ace.Account__c, ace.Level_2_Name__c, ace.Level_2_Email__c, ace.L2_Title__c);
system.debug('Account Case account '+ ace.Account__c);
system.debug('Account Case email '+ ace.Level_2_Email__c);
system.debug('Account Case name '+ ace.Level_2_Name__c);
system.debug('Account Case Title '+ ace.L2_Title__c);
}
}
Apex Class:
public with sharing class util
{
@future(callout=true)
public static void callwebservice(Id Accid, String name, String email, String title)
{
HTTP auth = new HTTP() ;
//List<contact> acc = [Select Id, Name from Account Where Id IN :recordIds];
//String Body = "Accountid":cid + "id":aid;
HTTPRequest r = new HTTPRequest();
r.setHeader('Content-Type','application/json');
String username = 'appviewxsupport2@yopmail.com';
String password = 'Appviewx@123';
Blob headerValue = Blob.valueOf(username+ ':' + password );
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
r.setHeader('Authorization', authorizationHeader);
r.setEndpoint('https://salesforceintegrationstaging.payoda.com/api/web/v1/accounts/updateaccountdetails');
r.setMethod('POST');
r.setBody('{"account_id":"accid","level_2_name":"name","level_2_email":"email","level_2_title":"title"}');
//r.setBody(body);
HTTPResponse authresp=new HttpResponse();
authresp = auth.send(r);
system.debug('Statuscode Expected'+ authresp.getStatusCode());
System.debug('Body expected' + authresp.getBody());
}
}
When I run the above code below the error i facing,
Error: System.HttpResponse[Status=Unauthorized, StatusCode=401
TIA
below my code,
Trigger:
trigger Level2Update on Account_Case_Escalation__c (after update) {
for(Account_Case_Escalation__c ACE: trigger.new)
{
util.callwebservice(ace.Account__c, ace.Level_2_Name__c, ace.Level_2_Email__c, ace.L2_Title__c);
system.debug('Account Case account '+ ace.Account__c);
system.debug('Account Case email '+ ace.Level_2_Email__c);
system.debug('Account Case name '+ ace.Level_2_Name__c);
system.debug('Account Case Title '+ ace.L2_Title__c);
}
}
Apex Class:
public with sharing class util
{
@future(callout=true)
public static void callwebservice(Id Accid, String name, String email, String title)
{
HTTP auth = new HTTP() ;
//List<contact> acc = [Select Id, Name from Account Where Id IN :recordIds];
//String Body = "Accountid":cid + "id":aid;
HTTPRequest r = new HTTPRequest();
r.setHeader('Content-Type','application/json');
String username = 'appviewxsupport2@yopmail.com';
String password = 'Appviewx@123';
Blob headerValue = Blob.valueOf(username+ ':' + password );
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
r.setHeader('Authorization', authorizationHeader);
r.setEndpoint('https://salesforceintegrationstaging.payoda.com/api/web/v1/accounts/updateaccountdetails');
r.setMethod('POST');
r.setBody('{"account_id":"accid","level_2_name":"name","level_2_email":"email","level_2_title":"title"}');
//r.setBody(body);
HTTPResponse authresp=new HttpResponse();
authresp = auth.send(r);
system.debug('Statuscode Expected'+ authresp.getStatusCode());
System.debug('Body expected' + authresp.getBody());
}
}
When I run the above code below the error i facing,
Error: System.HttpResponse[Status=Unauthorized, StatusCode=401
TIA
1.Bad request URL. Copy-pasting URL from your code to a browser may validate.
2.Wrong protocol. If the endpoint requires HTTPS and your URL uses HTTP.
3.Bad IP. You said that the provider has whitelisted the SFDC IPs, but perhaps they made an error. If you are able to test from a browser from a non-4.whitelisted IP (e.g., from home), you can determine if you get the same error.
5.Some other error at the endpoint. If everything else fails, you may need to ask the provider to check their logs.
Can you send the Same API call from the using POSTMAN and see
Thanks the response, I tried all the above, nothing came out, I postman its working fine.
what I see here is I have to pass the access token, that were i got stuck
https://salesforce.stackexchange.com/questions/143506/how-to-get-access-token-in-apex-scheduler-for-the-same-org
Hi Manojkumar,
![User-added image](/forums/servlet/rtaImage?eid=9072I000000EEkS&feoid=Body&refid=0EM2I000000ACWe)
This issue is stemming from the fact that you might be using invalid credentials. When i directly used the url and user+pass into browser url below is the response xml.
hope this helps!
Regards,
Santosh.
Yes, its because we are not passing the access token