+ Start a Discussion
vandana rajuvandana raju 

invalid session_Id in rest api resource

I am newbie to apex integration , I got the below error while peforming integration
"Invalid session_ID"

I am using two different saleforce instances to perform integration say HDFC & flipkart
HDFC is destination salesforce which contains a method which I need to call from flipkart(source )

In destionation instance: I have connected app, with client ID, consumer secret working
here is the code.
code in destination:
global class RestAccountUsingPatch
webservice static void UpdateAccount()  
   Account account=[SELECT Id,Name,Phone FROM Account WHERE Id=:RestContext.request.params.get('accountId')];
   account.Name='Cathay Pacific1';

   //I want to update phone.

code in source:
Helper class for OAUTH authentication.

In reqbody , I have provided the password and security_token of destination along with clientID and clientsecret
of destination

global class Helper
  global static OAuth2 GetAccessToken()
    Http h = new Http();
    HTTPRequest req = new HttpRequest();
    req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
    string reqbody ='grant_type=password&client_id=3MVG9ZL0ppGP5UrCfQLl3qwiw0BYov5r1NNhhhJkvj7VEeQtGzp4ki8zGexr7_XbvXdr1tzWhlDFEckNw5l91&client_secret=8280221851649175782&username=hdfcBank@sfdc.com&password=pwd+securitytoken of destination';      
    HttpResponse res=h.send(req);  
    OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
    return objAuthenticationInfo;
  global class OAuth2 
         public String id{get;set;}
         public String issued_at{get;set;}
         public String instance_url{get;set;}
         public String signature{get;set;}
         public String access_token{get;set;}    

//apex class
public class IntegrateAccountRestController
    public string jsonList;
    public List<Account> accList{get;set;}
    public PageReference pRef;
    public Account a { get; set; }

    public IntegrateAccountRestController()
      a = new Account();  

   public PageReference UpdateAccount()  
       if (Helper.GetAccessToken() != NULL)
          Http h = new Http();
          HttpRequest req = new HttpRequest();
          req.setHeader('Authorization','Bearer '+Helper.GetAccessToken().access_token);
          req.setHeader('Content-Type','application/json; charset=UTF-8'); 
          String dataupload = JSON.serialize(a);
          HttpResponse res=h.send(req); // JSON string is generated at this point
          Jsonresponse=res.getBody();//to get back the response from HDFC
        return null;
} //end of  IntegrateAccountRestController class

In source I have created remote site settings for the below urls

when I check debug logs, OAUTH = NULL,, so it is giving error as Invalid session_D
Please help me out.

Vandana R