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
ashish raiashish rai 

How to make http request with access token

Hi all,

   can any one help we the exact httpreqest with access token . I am using this but getiing a response "Bad_OAuth_Token" which comes when you are passing the wrong token.  

 

httprequest hreq=new httprequest();

hreq.Setendpoint('https://login.salesforce.com/id/00D90000000aSjoEAE/00590000000eb7cAAA');

hreq.setmethod('POST');

hreq.setHeader('Authorization: ','OAuth 00D90000000aSjo!AQgAQNfbCS3aunHX37ko2VhwXzk4holpYFrU9juuCIMdanXC54DAjI916nYNvzZHjOV2vRubCiT1XZGeongMBAVxtdMfpLlN');


hreq.setHeader('Host','https://ap1.salesforce.com');

http htp=new http();

httpResponse res=htp.send(hreq);system.debug('%%%%%%%%%%%%%' +res);

System.debug('@@@@@@@@' +res.getBody());

 

Can any one help me on this???????????????

SuperfellSuperfell

Take the colon out of the Authoriztion string in your call to setHeader.

There's also no need to set the Host header, that'll be done for you.

And i beleive the Id endpoint is expecting a GET request, not a POST.

ashishrai4uashishrai4u

Hi Simon,

       Can you post the exact httprequest having access token. Please go through the below that what i am doing wrong in that

because i am geting the same response that is Bad_OAuth_Token. When i remove the set  host header the response i am geting is null.  Please help me on that:

 

httprequest hreq=new httprequest();

hreq.Setendpoint('https://login.salesforce.com/id/00D90000000aSjoEAE/00590000000eb7cAAA');

hreq.setmethod('GET');

hreq.setHeader('Authorization',':OAuth 00D90000000aSjo!AQgAQIRuHIv1pXGwo306PxvZCcgeDp_S__T1jWwarX9KNUzCQO74prs0xPfoE49S7GGHWUkubZlA.q_6N34TPj9036UaPNPt');


//hreq.setHeader('Host','https://ap1.salesforce.com');

http htp=new http();

httpResponse res=htp.send(hreq);
system.debug('%%%%%%%%%%%%%' +res);

System.debug('@@@@@@@@' +res.getBody());