I am using salesforce-python-toolkit to connect to Salesforce SOAP API. I know how to connect to it using [user, password and security token]. But recently I have learned that I can connect to soap api using access token too. I just have to set access token in session header.

So I tried below code.

from sforce.partner import SforcePartnerClient
wsdl = '/path/to/partner.wsdl.xml'
fieldsDict = {}
fieldsDict[packagePrefix + 'external_field__c'] = externalField
fieldsDict[packagePrefix + 'status__c'] = deliveryStatus
client = SforcePartnerClient(wsdl)
header = client.generateHeader('SessionHeader')
header.sessionId = accessToken
header.serverUrl = serverUrl
sObjects = []
sObject = client.generateObject(packagePrefix + 'package__c')
for (k,v) in fieldsDict.items():
    setattr(sObject, k, v)
result = client.upsert(packagePrefix + 'external_field__c', sObject)

But I am getting an error saying

Destination URL not reset. The URL returned from login must be set in the SforceService

I checked that the header only has sessionId attribute.

# ipython prompt
In [14]: header = client.generateHeader('SessionHeader')
In [15]: header
   sessionId = None

So there is no point in setting location/serverUrl attributes in header.

If it's any help, we can do number of operations on client (using salesforce-python-toolkit)

In [16]: client.
client.convertLead                    client.getServerTimestamp            client.setAllowFieldTruncationHeader
client.create                         client.getSessionId                   client.setAssignmentRuleHeader
client.delete                         client.getUpdated                     client.setCallOptions
client.describeGlobal                 client.getUserInfo                    client.setEmailHeader
client.describeLayout                 client.invalidateSessions             client.setLocaleOptions
client.describeSObject                client.login                          client.setLoginScopeHeader
client.describeSObjects               client.logout                         client.setMruHeader
client.describeTabs                   client.merge                          client.setPackageVersionHeader
client.emptyRecycleBin                client.process                        client.setPassword
client.generateHeader                 client.query                          client.setQueryOptions
client.generateObject                 client.queryAll                       client.setSessionHeader
client.getConnection                  client.queryMore                      client.setStrictResultTyping
client.getDeleted                     client.resetPassword                  client.setUserTerritoryDeleteHeader
client.getLastRequest                 client.retrieve                       client.undelete
client.getLastResponse                client.search                         client.update
client.getLocation                    client.sendEmail                      client.upsert

Can you tell me where to put this url? I am not sure which url the error is referring to either. Is it

https://login.salesforce.com/id/xxxxxxxxxx/yyyyyyyyyyyy   OR

Please help me out here. Thanks.


I think you need to call


The Partner API Server URL should be of the form


For example


If you've done OAuth, you can easily obtain the Partner API Server URL by calling the Identity Service. Append ?version=latest to the id property of the OAuth response, passing the access token in the Authorization HTTP header - see the documentation on Identity URLs for details. The Partner API Server URL is in the response, at urls.partner.

| improve this answer | |
  • It works! You are the best! Made a GET request with header to the identityUrl - response = requests.get(identityUrl, headers=headers) and got the serverUrl ['urls']['partner']. Called _setEndpoint and it works. – Hussain Tamboli Oct 21 '14 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.