I'm working on Salesforce integration
to (1) upload file attachments to Salesforce and (2) make signed requests/API call to Salesforce using the access token that we already have. Uploading files to SF using REST is not an option for us since we are not in pilot program as describe here. So we used Beatbox to upload files to SF and that uses SOAP api. Now since we're using Beatbox we also wanted to make signed request to SF API using an access token that we already have. Looking at Beatbox source there is useSession(sessionId, serverUrl)
, now I can replace sessionId
with access token
and put a hard coded server url and I can make signed request to SF with that, problem is serverUrl
is changing. Using just the access token can I get the serverUrl in advance so that I can use it with useSession()
? If not possible, what are other alternatives?
Update: I added a simple helper method to beatbox.py for our requirement though some might find it useful. Credits to metadaddy for the solution.
def oauth_login(self, sessionId, orgId, userId):
url = 'https://login.salesforce.com/id/%s/%s' % (orgId, userId)
headers = {
'Authorization': 'Bearer %s' % sessionId
}
params = {'version':'latest'}
resp = requests.post(url, params=params, headers=headers, allow_redirects=True)
content = json.loads(resp.content)
serverUrl = str(content.get('urls')['partner']).encode('UTF-8')
self.useSession(sessionId, serverUrl)
Usage:
import beatbox
sf = beatbox._tPartnerNS
svc = beatbox.Client()
access_token = ''
orgId = ''
userId = ''
svc.oauth_login(access_token, orgId, userId)
qr = svc.query("select Id, Name from Account")
print "query size = " + str(qr[sf.size])