Create tenant with roles, groups, and users
This example uses the REST API to create a tenant with its roles, groups, and users, the way a service provider onboards a new customer. It uses curl to send the requests.
Prerequisites
- A user account for the integration, created in the MiaRec web portal. In this example, its login
is
apiuserand its password issecret. Its role has the REST API permission and permissions to create tenants, roles, groups, and users. The account belongs to the System tenant; a tenant user cannot create tenants. - The address of your MiaRec web portal. The examples use
https://{your-miarec-server}.
The example creates:
- A tenant named "Acme Tenant"
- Two roles: "Group Manager Role" and "Agent Role"
- Two groups: "Managers Group" and "Agents Group"
- Two users, one in each group
Step 1. Verify the REST API connection
Retrieve the list of tenants:
curl -u apiuser:secret https://{your-miarec-server}/api/v2/tenants.json
The expected result looks like the following. If you see an error instead, check the credentials and the role permissions of the API user (see Security and authentication).
{
"tenants": [
{
"tenant_id": "34c7f1f6-9201-11e5-a739-e03f497dbdff",
"name": "Flexus",
"timezone": null,
"encrypt_data": false,
"fieldset_licensing": {
"recording_seats": 20,
"recording_sessions": null,
"screen_recording_seats": 0,
"monitoring_seats": 10,
"evaluation_seats": 20,
"speech_analytics": 20
},
...
},
...
],
"total": 8,
"next_url": null
}
Step 2. Create the tenant
Save the tenant data in a file named add_tenant.json:
{
"tenant": {
"name": "Acme Tenant",
"timezone": "Europe/London",
"encrypt_data": false,
"fieldset_licensing": {
"recording_seats": 50,
"evaluation_seats": 50
}
}
}
Attributes that are not included take their default values. See Tenant object fields.
Submit the request:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_tenant.json" https://{your-miarec-server}/api/v2/tenants.json
When the tenant is created, the response contains the URL of the new tenant:
{"url": "/api/v2/tenants/00416392-cf76-11e5-a728-e03f497dbdff.json"}
Retrieve the tenant to confirm:
curl -u apiuser:secret https://{your-miarec-server}/api/v2/tenants/00416392-cf76-11e5-a728-e03f497dbdff.json
Step 3. Create the roles
Create two roles: "Group Manager Role" and "Agent Role". Set tenant_id to the ID of the tenant
from the previous step, 00416392-cf76-11e5-a728-e03f497dbdff in this example. See
Role object fields.
Save the following in add_role_manager.json:
{
"role": {
"name": "Group Manager Role",
"access_level": "managed_groups",
"tenant_id": "00416392-cf76-11e5-a728-e03f497dbdff",
"permissions": {
"calls": [
"categorize",
"playback",
"pause_recording",
"live_monitor",
"view",
"on_demand_trigger",
"add_notes"
],
"call_categories": [
"view",
"delete",
"edit"
],
"call_notes_own": [
"view",
"pin",
"delete"
],
"call_notes": [
"view",
"pin"
]
}
}
}
Save the following in add_role_agent.json:
{
"role": {
"name": "Agent Role",
"access_level": "user",
"tenant_id": "00416392-cf76-11e5-a728-e03f497dbdff",
"permissions": {
"calls_own": [
"view",
"categorize",
"playback",
"pause_recording",
"on_demand_trigger",
"add_notes"
],
"call_categories": [
"view",
"delete",
"edit"
],
"call_notes_own": [
"view",
"pin",
"delete"
],
"call_notes": [
"view",
"pin"
]
}
}
}
Submit the first role:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_role_manager.json" https://{your-miarec-server}/api/v2/roles.json
The response contains the URL of the new role:
{"url": "/api/v2/roles/e4195b2c-cf78-11e5-9367-e03f497dbdff.json"}
Submit the second role:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_role_agent.json" https://{your-miarec-server}/api/v2/roles.json
The response:
{"url": "/api/v2/roles/14e1c064-cf79-11e5-9804-e03f497dbdff.json"}
Step 4. Create the groups
Create two groups: "Managers Group" and "Agents Group", again with the tenant_id of the new
tenant. See Group object fields.
Save the following in add_group_managers.json:
{
"group": {
"tenant_id": "00416392-cf76-11e5-a728-e03f497dbdff",
"name": "Managers Group"
}
}
Save the following in add_group_agents.json:
{
"group": {
"tenant_id": "00416392-cf76-11e5-a728-e03f497dbdff",
"name": "Agents Group"
}
}
Submit the first group:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_group_managers.json" https://{your-miarec-server}/api/v2/groups.json
The response contains the URL of the new group:
{"url": "/api/v2/groups/5fce93a8-cf7a-11e5-8e94-e03f497dbdff.json"}
Submit the second group:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_group_agents.json" https://{your-miarec-server}/api/v2/groups.json
The response:
{"url": "/api/v2/groups/7248c8f0-cf7a-11e5-adb9-e03f497dbdff.json"}
Step 5. Create the users
Create two users. See User object fields.
- Peter has the "Group Manager Role" and is a member of "Managers Group". Peter also manages "Agents Group".
- David has the "Agent Role" and is a member of "Agents Group".
Save the following in add_user_peter.json:
{
"user": {
"name": "Peter",
"is_active": true,
"role_id": "e4195b2c-cf78-11e5-9367-e03f497dbdff",
"groups": ["5fce93a8-cf7a-11e5-8e94-e03f497dbdff"],
"managed_groups": [
"7248c8f0-cf7a-11e5-adb9-e03f497dbdff"
],
"timezone": "Europe/London",
"fieldset_login": {
"can_login": true,
"login": "peter",
"password": "secret",
"authenticate_type": "password"
},
"fieldset_recording": {
"extensions": ["2001", "2002"],
"record": "always",
"record_direction": ["in", "out"]
},
"fieldset_licensing":
{
"recording_seat": true
}
}
}
Replace the following values with the IDs returned in the previous steps:
role_id: the ID of "Group Manager Role"groups: the ID of "Managers Group"managed_groups: the IDs of the groups the user manages, here the ID of "Agents Group"
Submit the request:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_user_peter.json" https://{your-miarec-server}/api/v2/users.json
The response contains the URL of the new user:
{"url": "/api/v2/users/34e2ac80-9201-11e5-93e4-e03f497dbdff.json"}
Save the following in add_user_david.json:
{
"user": {
"name": "David",
"is_active": true,
"role_id": "14e1c064-cf79-11e5-9804-e03f497dbdff",
"groups": ["7248c8f0-cf7a-11e5-adb9-e03f497dbdff"],
"timezone": "Europe/London",
"fieldset_login": {
"can_login": true,
"login": "david",
"password": "secret",
"authenticate_type": "password"
},
"fieldset_recording": {
"extensions": ["123456"],
"record": "always",
"record_direction": ["in", "out"]
},
"fieldset_licensing":
{
"recording_seat": true
}
}
}
Replace role_id with the ID of "Agent Role" and groups with the ID of "Agents Group", then
submit the request:
curl -u apiuser:secret -H "Content-Type: application/json" -X POST \
--data "@add_user_david.json" https://{your-miarec-server}/api/v2/users.json
Where to find all supported attributes
MiaRec is improved continuously and new attributes are added over time. To see the attributes that your version supports, retrieve an existing record and inspect the response:
curl -u apiuser:secret https://{your-miarec-server}/api/v2/tenants.json
curl -u apiuser:secret https://{your-miarec-server}/api/v2/roles.json
curl -u apiuser:secret https://{your-miarec-server}/api/v2/groups.json
curl -u apiuser:secret https://{your-miarec-server}/api/v2/users.json
The API Explorer of your server lists every attribute with its type and description. If the meaning of an attribute is unclear, change the setting in the web portal and compare the JSON before and after.
If you have questions, contact MiaRec support.