The answer to this question is yes. Simply use header:
X-SFDC-Session:<accessToken>
where <accessToken> should be replaced with your access token. In my case I got confused, because my access token had expired and the error was something like "Session ID is not valid" which made me believe that access tokens retrieved via OAuth couldn't be used.
this is a great question
it is possible!!
see this link
http://blog.sforce.com/sforce/2011/03/oauth-and-the-soap-api.html
Hi Roger,
Did you try the solution mentioned by Derek at http://blogs.developerforce.com/developer-relations/2011/03/oauth-and-the-soap-api.html
Did it work for you? If not what did you do to make it work. I have a similar requirement as yours, any informatioin from you will be very helpful.
Thanks,
Nilesh
Hi All,
I am using access token for bulk api request
req.setHeader('Authorization', 'OAuth 00D90000000nOZP!ARwAQJ6Y9P_fWr173CV5ezq9.DX_dVeyHh6U.k5Tr_WYbPqPf4YDYMASZaJzbNChthWuM1f9QF0vsVZufAJdv1JRIdODmy2i'
);
It is returning invalid session id . Cannot we use access token instead of session id in bulk request .
Regards,
Neha
I really wish this question was answered. I can't find it anywhere and they're only allowing me oauth and i need to use the bulk api :(
Hi
Hi,
You Can use access token in place of session id in bulk api .
Kindly find the below mentioned code which i used :
String boxClientID ='3MVG9Y6d_Btp4xp7ScbG6kWMdax2wg4G15Y_PHrFwv3YGsjejdcT9VbMvYiqQZNB1aAU9zlSanUwPNq7s3A4x';
String redirectURI ='https://ap1.salesforce.com/apex/BulkAPI';
Http h = new Http();
HttpRequest req = new HttpRequest();
string endPointValue = 'https://login.salesforce.com/services/oauth2/token';
req.setEndpoint(endPointValue);
req.setBody('Content-Type=' + EncodingUtil.urlEncode('application/JSON', 'UTF-8') +
'&charset=' + EncodingUtil.urlEncode('UTF-8', 'UTF-8') +
'&grant_type=' + EncodingUtil.urlEncode('password', 'UTF-8') +
'&client_id=' + EncodingUtil.urlEncode(boxClientID, 'UTF-8') +
'&client_secret=' + EncodingUtil.urlEncode('8271504369047854174', 'UTF-8') +
'&username=' + EncodingUtil.urlEncode('axeda_app@wipro.com', 'UTF-8') +
'&password=' + EncodingUtil.urlEncode('wipro123', 'UTF-8') +
'&redirect_uri=' + EncodingUtil.urlEncode(redirectURI, 'UTF-8'));
req.setMethod('POST');
HttpResponse res = h.send(req);
System.debug('****res***'+res.getbody());
OAuth objAuthenticationInfo = (OAuth)JSON.deserialize(res.getbody(), OAuth.class);
String respId=objAuthenticationInfo.id;
respAccesToken11=objAuthenticationInfo.access_token;
String respAccesToken=objAuthenticationInfo.access_token;
From external system below mentioned code will be used:
Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setMethod('POST');
req.setEndpoint('https://ap1.salesforce.com/services/async/28.0/job');
req.setHeader('X-SFDC-Session', ' ' + UserInfo.getSessionId()); // USE ACCESS TOKEN
req.setHeader('Content-Type', ' application/xml; charset=UTF-8');
res = null;
String jobXml =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">' +
'<operation>insert</operation>' +
'<object>Asset</object>' +
'<contentType>XML</contentType>' +
'</jobInfo>';
req.setBody(jobXml);
res = http.send(req); // HTTP response will return JOB ID
SYstem.debug('##################### ' + res.getBody()+'jobid*******'+res.getHeaderKeys());
where <accessToken> should be replaced with your access token. In my case I got confused, because my access token had expired and the error was something like "Session ID is not valid" which made me believe that access tokens retrieved via OAuth couldn't be used.