function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sidhartha Mohapatra 10Sidhartha Mohapatra 10 

Help required ..Invalid session id in salesforce rest api

I am getting Invalid session id when i am executing the below code. Please let me know where i am doing wrong.

public class ResttestController {

    public String response{get;set;}
    public String dccName{get;set;}

    public PageReference Donate() {
        //find access token using Auth 2.0 
        String Access_Token='##############################################.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$';
        Httprequest req=new httprequest();
        String domainName='ap2.salesforce.com';
        String endPointURL='https://'+domainName+'/services/data/v34.0/sobjects/Donations';
        req.setendpoint(endPointURL);
        req.setHeader('Content-Type', 'application/xml; charset=utf-8');
        req.setBody('<?xml version="1.0" encoding="UTF-8" ?><request><name>'+dccName+ </request>');
        req.setmethod('POST');
        req.setHeader('Authorization','Authorization: Bearer '+Access_Token);
        Http http = new Http();
        HTTPResponse res = http.send(req);
        response=res.getbody();
        return null;
    }
}
Regards
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
http://stackoverflow.com/questions/6095352/salesforce-rest-api-invalid-session-id-error

Please let us know if this will help you
Ritika.BhargavaRitika.Bhargava
Try 
req.setHeader('Authorization','Bearer '+Access_Token);
instead of
req.setHeader('Authorization','Authorization: Bearer '+Access_Token);

 
Sidhartha Mohapatra 10Sidhartha Mohapatra 10
Hi Ritika,

I am getting the same invalid session id error. Please let me know whtelse need to be checked.

Regards