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
cvsgcvsg 

Using web services session id and access token interchangeably

Hi,

 

I have a generated a sessionID using web services API (login call) and trying to use it as an accesstoken in a REST based request. It doesn''t seem to be working. Here is the link to documentation which talks about this. http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#StartTopic=Content/quickstart_oauth.htm

 

any help is appreciated

 

Thanks,

cvsg

 

SuperfellSuperfell

I do it all the time, can you post some more details on how its not working, what does your REST API request look like ?

cvsgcvsg

hi,

 

I use the below code.

 

HttpClient httpclient = new HttpClient();

GetMethod method = new GetMethod(https://ap1.salesforce.com/services/data/v20.0/sobjects/);

method.setRequestHeader("Authorization", "OAuth "+ <sessioind generated from web servics api>);

method.setRequestHeader("Accept-Encoding", "gzip");

httpclient.executeMethod(method);

 

 

SuperfellSuperfell

What error do you get? is your org actually on ap1 ?

cvsgcvsg

Hi,

 

I just found out where thr problem is. The problem is with serverurl retrieved from the loginresult object. It is in the format https://<servername>/services/Soap/u/20.0/00D900000000mBf. To create a REST based url, I am blindly appending "/services/data/v20.0/sobjects/" to the server url. I guess, I will have to parse the server url for server name and then append rest related paths to that.

 

Anyway, thanks a lot!

 

cvsg.