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
Yury.KYury.K 

oAuth 2.0, Access token as parameter

Hello everyone,
I'm using REST API to be authorized in Force.com, I have no problem with getting and using access token. Im using access token as header, everything works perfectly.

 

But I wonder if I can use access token, as parameter in URL?
So url parameter will look like :
&access_token=<access token>
Is it possible? If yes - which variable in parameter should I use ?

 

Thanks and Regards,
Yury.

Navatar_DbSupNavatar_DbSup

Hi,

 

You can send a request by setting access token in the header.

 

Try the below code snippet.

 

  http h1 = new http();

        httprequest req1 = new httprequest();

    

        req1.setEndpoint('https://ap1.salesforce.com/services/data/v20.0/sobjects/Account/');

        req1.setMethod('GET');

        req1.setHeader('Accept', 'application/xml;charset=UTF-8');   // When you use setMethod as 'GET' To get response in xml format.

    

        req1.setHeader('Authorization:', 'OAuth ' + acc_tken);  // you can set access Token here in the header, after this send your request

       // req1.setTimeout(60000);

 

        httpresponse res1 = h1.send(req1);

 

        string result1 = res1.getBody();

        system.debug('@@@@@@@@@@@@@@@@@@_________________________result__________________________' +result1);

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

Yury.KYury.K

I know how to send it in header, got this logic and it's working perfectly.

But in my scenario I need to use it in URL address(if its possible). 

 

Thanks and Regards,
Yury. 

 

Navatar_DbSupNavatar_DbSup

Hi,

 

The client application can use the access token to authorize requests against the resource server (the Force.com instance specified by the instance URL) via the REST APIs, providing the access token as an HTTP header in each request.

You can't use it in url.