Skip to content

Instantly share code, notes, and snippets.

@h3xh4wk
Created June 4, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3xh4wk/720572f1889257aa497ecb4cf24dda02 to your computer and use it in GitHub Desktop.
Save h3xh4wk/720572f1889257aa497ecb4cf24dda02 to your computer and use it in GitHub Desktop.
from suds.client import Client
from suds.sax.element import Element
url = "file:///home/jitendra/obs/wsdl.jsp.xml"
client = Client(url)
token = "xxxxxxxxxxxxxxxxxxxxxxxx"
print client
LoginResult = client.service.login("userId", "pwd"+token)
#Specifies the server URL as the target for subsequent service requests. The login server supports only login calls.
client.wsdl.services[0].setlocation(LoginResult.serverUrl)
#Sets the session ID in the SOAP header so that the API can validate subsequent requests for this session.
ssnp = Element("xsi:SessionHeader").append(Element('xsi:sessionId').setText(LoginResult.sessionId))
client.set_options(soapheaders=ssnp)
LogOutResult = client.service.logout()
print LoginResult
print client.last_sent()
print client.last_received()
@h3xh4wk
Copy link
Author

h3xh4wk commented Dec 14, 2016

Well, I didn't know that I could achieve the same thing in lesser lines of code.

svc = pyforce.PythonClient(serverUrl='https://test.salesforce.com/services/Soap/u/20.0')
LoginResult = svc.login(username='mysandboxusername', passwd='mypassword')
svc.logout()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment