pythonsalesforcebulk

How to login to the sandbox using salesforce Bulk API


I'm trying to use python to connect to Salesforce Bulk API. However, I don't want to test my code on the real salesforce. I want to test with my sandbox. However, I don't know how to connect to sandbox only... I've tried to add sandbox=True but it doesn't work...

import salesforce_bulk

bulk=salesforce_bulk.SalesforceBulk(username="username",password="password")

Solution

  • Old question but I had the same problem today, so maybe this will help someone.

    This is a complete hack, but it works - probably a better hack would be to do this using salesforce-oauth-request (which does have a "sandbox=True" option), but I was logging in via beatbox anyway, so tried this first.

    Gist is you log in to the sandbox using beatbox (which lets you specify your serverUrl) and then use that sessionId and instance_url to log in through salesforce_bulk.

    import beatbox
    from salesforce_bulk import SalesforceBulk
    
    # log in to sandbox using beatbox
    service = beatbox.PythonClient()
    
    service.serverUrl = 'https://test.salesforce.com/services/Soap/u/20.0'
    user = 'user@user.com'
    password = 'secret'
    token = '12345'
    
    service.login(user, password+token)
    
    # the _Client_serverUrl has the instance url + some 
    # SOAP stuff, so we need to strip that off
    groups = service._Client__serverUrl.split('/')
    instance_url = '/'.join(groups[:3])
    
    # now we can use the instance_url and sessionId to 
    # log into Salesforce through SalesforceBulk
    bulk = sfdc_bulk_connect(instance_url, service.sessionId)