jonathanvieira | 2018-05-18 17:59:06 UTC | #1
I'm trying to post a single contact into the contact list, but still getting 400 Bad Request - he request could not be understood by the server due to malformed syntax.
This is my Code
import base64, requests, sys, json
clientId = 'xxxxxxx' clientSecret = 'xxxxxxx' contactListId = '65369684-6c7e-4a06-89be-9ec53d414c46'; url = 'https://login.mypurecloud.com/oauth/token'; url_contact = 'https://api.mypurecloud.com/api/v2/outbound/contactlists/'+ contactListId + '/contacts';
authorization = base64.b64encode(clientId + ':' + clientSecret)
requestHeaders = { 'Authorization': 'Basic ' + authorization, 'Content-Type': 'application/x-www-form-urlencoded' } requestBody = { 'granttype': 'clientcredentials' }
response = requests.post(url, data=requestBody, headers=requestHeaders)
if response.statuscode == 200: print 'Got token' else: print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason sys.exit(response.status_code)
responseJson = response.json()
requestHeaders = { 'Authorization': responseJson['tokentype'] + ' ' + responseJson['accesstoken'], 'Content-Type': 'application/json' }
contactData = { 'name': 'update', 'contactListId': contactListId, 'data': { 'nome': 'Jonathan Teste PY', 'cpf': '081.111.111-20', 'telefone': '5548999223110', 'email': 'pytest@e.com' }, 'callable': True, 'phoneNumberStatus': {} }
response = requests.post(url_contact, data=contactData, headers=requestHeaders)
if response.statuscode == 200: print 'Got Update Contact List' else: print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason sys.exit(response.json())
print '\nDone'
system | 2018-06-18 17:57:51 UTC | #2
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 2888