DataService web service with Python 3: login, sesión and get rows
import json
import requests
login_url = "https://my.bpmonline.com/ServiceModel/AuthService.svc/Login"
headers = {"Content-Type": "application/json"}
login_json = {"UserName": "Supervisor", "UserPassword": "password"}
# Login and get the session cookie
session = requests.post(login_url, headers=headers, json=login_json)
select_url = 'https://my.bpmonline.com/0/dataservice/json/reply/SelectQuery'
# Set the http header BPMCSRF to run the JSON query
headers['BPMCSRF'] = session.cookies.get_dict()['BPMCSRF']
# The JSON query to DataService
select_contact_json = {
"RootSchemaName":"Contact",
"OperationType":0,
"Columns":{
"Items":{
"GivenName":{
"Expression":{
"ExpressionType":0,
"ColumnPath":"GivenName"
}
},
"MiddleName":{
"Expression":{
"ExpressionType":0,
"ColumnPath":"MiddleName"
}
},
"Surname":{
"Expression":{
"ExpressionType":0,
"ColumnPath":"Surname"
}
},
"BirthDate":{
"Expression":{
"ExpressionType":0,
"ColumnPath":"BirthDate"
}
}
}
},
"AllColumns":1
}
select_contact_response = requests.post(select_url, headers=headers, cookies=session.cookies, json=select_contact_json)
select_contact_json_data = json.loads(select_contact_response.text)
# print(select_contact_response.status_code)
print(select_contact_response.text)