Last active
February 21, 2019 14:20
-
-
Save krypted/40fe144153daa7908ccf034bc3b02d90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from xml.etree import ElementTree as ET | |
import sys | |
print("Script Starting...") | |
print("") | |
# Set the following constants specific to Salesforce Environment | |
username = sys.argv[1] | |
password = sys.argv[2] | |
url = "https://login.salesforce.com/services/Soap/c/42.0" | |
security_token = "YOURTOKENHERE" | |
# No changes required below | |
headers = {'content-type': 'text/xml;charset=UTF-8', 'SOAPAction': 'login'} | |
body = """<?xml version="1.0" encoding="UTF-8"?> | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com"> | |
<soapenv:Body> | |
<urn:login> | |
<urn:username>""" + username + """</urn:username> | |
<urn:password>""" + password + security_token + """</urn:password> | |
</urn:login> | |
</soapenv:Body> | |
</soapenv:Envelope>""" | |
# Call the login method | |
response = requests.post(url, data=body, headers=headers) | |
xml = response.content | |
# Parse the response | |
root = ET.fromstring(xml) | |
# Print the complete response | |
print("Salesforce Response ==> ") | |
ET.dump(root) | |
print("") | |
# Print few attributes | |
print("User Name ==> " + root.find('.//{urn:enterprise.soap.sforce.com}userFullName').text) | |
print("User Email ==> " + root.find('.//{urn:enterprise.soap.sforce.com}userEmail').text) | |
print("") | |
print("Script Completed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment