Hello,
Please find below a python example tested successfully in 6.2.6.
#!/usr/bin/env python
#==============================================================================
import argparse
import httplib2
import json
import urllib
#==============================================================================
def portal_login(url,username,password,disable_cert_validation):
http = httplib2.Http(disable_ssl_certificate_validation=disable_cert_validation)
API=“/loginservice”
URL=url+API
body={‘username’: username, ‘password’: password, ‘redirect’: ‘false’}
headers={“Content-type”:“application/x-www-form-urlencoded”}
response, content = http.request(URL,‘POST’,headers=headers,body=urllib.urlencode(body))
if response.status!=200:
raise Exception("HTTP STATUS: "+str(response.status))
return response[‘set-cookie’]
#==============================================================================
def create_group(url,cookie,name,disable_cert_validation):
http = httplib2.Http(disable_ssl_certificate_validation=disable_cert_validation)
API=“/API/identity/group/”
URL=url+API
headers={“Content-type”:“application/json”,‘Cookie’: cookie}
data={“icon”:“”,“name”:name,“displayName”:“”,“parent_group_id”:“”,“description”:“”}
data = json.dumps(data)
response, content = http.request(URL, ‘POST’,headers=headers, body=data)
if response.status!=200:
raise Exception("HTTP STATUS: “+str(response.status)+” "+content)
else:
data = json.loads(content)
return data[‘id’]
#==============================================================================
def main():
parser = argparse.ArgumentParser(description=‘Create a Bonita group’,
add_help=False)
# required arguments
required = parser.add_argument_group(‘required arguments’)
required.add_argument(“–login”,
required=True,
help=“Account used to authenticate you on Bonita”,
metavar=“install”)
required.add_argument(“–password”,
required=True,
help=“Password used with your account”,
metavar=“install”)
required.add_argument(“–url”,
required=True,
help=“Bonita BPM url”,
metavar=“http://example.com:8080/bonita”)
required.add_argument(“–name”,
required=True,
help=“Group name”,
metavar=“México”)
# optional arguments
optional = parser.add_argument_group(‘optional arguments’)
optional.add_argument(‘-h’, ‘–help’,
action=‘help’,
help=“Show this help message and exit”)
optional.add_argument(“–disable_ssl_certificate_validation”,
help=“Used this only for tests with a self-signed certificate”,
action=“store_true”)
args = parser.parse_args()
cookie=portal_login(args.url,args.login,args.password,args.disable_ssl_certificate_validation)
gid=create_group(args.url,cookie,args.name,args.disable_ssl_certificate_validation)
#==============================================================================
if name == “main”:
main()
./create_bonita_group.py --login install --password install --url http://127.0.0.1:8080/bonita --name México
More details regarding json.dumps are available here https://docs.python.org/2/library/json.html