You need to sign in to do that
Don't have an account?
Zachariah Rosenberg
REST API: Authentication by Session id
Hello,
I'm going through the Salesforce API REST guide, and I'm trying to authenticate via session id. My script is in python:
import urllib, urllib2
url = 'https://login.salesforce.com/services/oauth2/token'
values = {
"grant_type":"password",
"client_id":"aaaaaaaaaaaa11111111111111",
"client_secret":"1111111111111",
"username":"myuser@domain.com",
"password":"mypassword"
}
data = urllib.urlencode(values)
req = urllib2.Request(url,data)
sf = urllib2.urlopen(req)
I'm receiving a 400 Error:
Traceback (most recent call last):
File "/Users/ZR/Desktop/sf.py", line 14, in <module>
sf = urllib2.urlopen(req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
[Finished in 0.4s with exit code 1]
Where have I gone wrong?
Thank you!
I'm going through the Salesforce API REST guide, and I'm trying to authenticate via session id. My script is in python:
import urllib, urllib2
url = 'https://login.salesforce.com/services/oauth2/token'
values = {
"grant_type":"password",
"client_id":"aaaaaaaaaaaa11111111111111",
"client_secret":"1111111111111",
"username":"myuser@domain.com",
"password":"mypassword"
}
data = urllib.urlencode(values)
req = urllib2.Request(url,data)
sf = urllib2.urlopen(req)
I'm receiving a 400 Error:
Traceback (most recent call last):
File "/Users/ZR/Desktop/sf.py", line 14, in <module>
sf = urllib2.urlopen(req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
[Finished in 0.4s with exit code 1]
Where have I gone wrong?
Thank you!
Add the security token with the password, Looking at the docs :
https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_username_password_flow.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_username_password_flow.htm&language=en)
There is a mention here that says :
You must concatenate their password and token when passing the request for authentication.
All Answers
Add the security token with the password, Looking at the docs :
https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_username_password_flow.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_username_password_flow.htm&language=en)
There is a mention here that says :
You must concatenate their password and token when passing the request for authentication.
Where do I get the security token from?