Skip to main content
ManojKumar Muthu (Appviewx) 님이 #Integration에 질문했습니다
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

 
답변 5개
  1. 2019년 4월 2일 오후 3:25

    Hi Manojkumar,

    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.

    Hi Manojkumar,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.

0/9000