jcputter | 2017-01-31 20:16:34 UTC | #1
Hi
I'm trying the Python Example but getting a HTTP 400, what's missing?
https://developer.mypurecloud.com/api/tutorials/oauth-client-credentials/#python
Thanks in advance
tim.smith | 2017-01-31 20:21:20 UTC | #2
A 400 response means "bad request". Can you provide some more info on what resource you're using, the response body, etc?
jcputter | 2017-02-01 05:16:14 UTC | #3
Hi
I'm using the example on the URL as is.
jcputter | 2017-02-02 07:43:06 UTC | #4
Can you explain why the example provided does not work?
tim.smith | 2017-02-02 16:51:03 UTC | #5
Can you provide some more info on what resource you're using, the response body, etc? I don't have much to go on knowing that something somewhere is giving you a 400. There's multiple requests in the example and the response bodies typically contain information that's helpful for troubleshooting.
jcputter | 2017-02-07 07:42:45 UTC | #6
<pre> response = requests.post('https://login.mypurecloud.com/oauth/token', data=requestBody, headers=requestHeaders)
if response.statuscode == 200: print 'Got token' else: print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason sys.exit(response.status_code) <pre>
jcputter | 2017-02-07 07:41:39 UTC | #7
<pre>clientId = 'xxxx' clientSecret = 'xxxxx' authorization = base64.b64encode(clientId + ':' + clientSecret)
requestHeaders = { 'Authorization': 'Basic ' + authorization, 'Content-Type': 'application/x-www-form-urlencoded' } requestBody = { 'granttype': 'clientcredentials' }
response = requests.post('https://login.mypurecloud.com/oauth/token', data=requestBody, headers=requestHeaders)
if response.statuscode == 200: print 'Got token' else: print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason sys.exit(response.status_code) <pre>
KevinGlinski | 2017-02-07 11:31:43 UTC | #8
are you trying to connect to the .com or .ie regions? If you aren't connecting to .com, you need to change https://login.mypurecloud.com to the correct region
tim.smith | 2017-02-07 14:46:13 UTC | #9
After you switch to the correct region, I'd like to see the response you're getting if it's still not working. What does this code output?
if response.status_code == 200:
print 'Got token'
else:
print 'Failure: ' + str(response.status_code) + ' - ' + response.reason
sys.exit(response.status_code)
jcputter | 2017-02-08 07:14:33 UTC | #10
Hi Yes that was the issue. Thanks
system | 2017-08-28 19:31:47 UTC | #11
This post was migrated from the old Developer Forum.
ref: 873