Creating Roles

Creating Roles

The Backend Services RESTful API allows you to create roles using HTTP requests. The operation requires Master Key authentication.

You can create either a single role by passing the role item in a JSON format or multiple roles with a single call passing an array.

Creating a Single Role

To create a role, you need to pass pass a JavaScript object containing the Name property of the role:

$.ajax({
    type: "POST",
    url: 'https://api.everlive.com/v1/Metadata/Applications/project-id/Roles',
    headers: {
        "Authorization" : "Masterkey your-master-key"
    },
    contentType: "application/json",
    data: JSON.stringify({
        "Name" : "Guests"
    }),
    success: function(data){
        alert(data.Id);
    },
    error: function(error){
        alert(error.message);
    }
})
Request:
    POST https://api.everlive.com/v1/Metadata/Applications/project-id/Roles
Headers:
    Authorization  Masterkey your-master-key
    Content-Type: application/json
Payload - raw:
    {
        "Name" : "Guests"
    }
Response:
    Status: 201 Created
    Content-Type: application/json

After creating the role, the server returns the ID of the created item along with its creation date:

STATUS 201 Created
{
    "Result": {
        "Id": "4839eb70-23e0-11e5-8f10-7192c7d7169d",
        "CreatedAt": "2015-07-06T13:09:49.607Z"
    }
}

Creating Multiple Roles

To create multiple roles with a single request, pass an array of objects representing a single role each:

var multiple = [
    {
        "Name" : "Guests"
    },
    {
        "Name" : "Special"
    } ];

$.ajax({
    type: "POST",
    url: 'https://api.everlive.com/v1/Metadata/Applications/project-id/Roles',
    headers: {"Authorization" : "Masterkey "},
    contentType: "application/json",
    data: JSON.stringify(multiple),
    success: function (data) {
        alert(JSON.stringify(data));
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
})
Request:
    POST https://api.everlive.com/v1/Metadata/Applications/project-id/Roles
Headers:
    Authorization  Masterkey your-master-key
    Content-Type  application/json
Payload - raw:
    [
        {
            "Name" : "Guests"
        },
        {
            "Name" : "Special"
        } ]
Response:
    Status: 201 Created
    Content-Type: application/json

The success server response contains the ID of the created item along with its creation date.

STATUS 201 Created
{
    "Result": [
        {
            "Id": "c6e67040-23e2-11e5-806b-8bda938bf226",
            "CreatedAt": "2015-07-06T13:27:41.124Z"
        },
        {
            "Id": "c6e67041-23e2-11e5-806b-8bda938bf226",
            "CreatedAt": "2015-07-06T13:27:41.124Z"
        }
    ]
}

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.