Creating Data Items

Creating Data Items

With a Backend Services RESTful API call, you can create either a single item by passing it in a JSON format or multiple items by passing an array.

Creating a Single Item

The following code snippet creates the item defined in the request body in the content type specified in the request URL. On success, the server returns the ID of the created item alongside its creation date.

Request:
    POST http://api.everlive.com/v1/your-app-id/type-name
Headers:
    Authorization Bearer your-access-token
    Content-Type application/json
Body:
    {
        "Author" : "Sample value"
    }

Response:
    Status: 201 Created
Content-Type:
    application/json
Body:
    {
        "Result": {
            "Id": "5ca8b640-b8ff-11e5-bdcd-49387e6215a1",
            "CreatedAt": "2016-01-12T07:37:41.540Z"
        }
    }
var object = { "Author" : "Sample value" };

$.ajax({
    type: "POST",
    url: 'http://api.everlive.com/v1/your-app-id/type-name',
    headers: { "Authorization" : "Bearer your-access-token" },
    contentType: "application/json",
    data: JSON.stringify(object),
    success: function(data) {
        alert(JSON.stringify(data));
    },
    error: function(error) {
        alert(JSON.stringify(error));
    }
})

Creating Multiple Items

To create multiple content type items in a single operation, you need to pass an array of objects.

Request:
    POST http://api.everlive.com/v1/your-app-id/type-name
Header:
    Authorization Bearer your-access-token
Body:
    [
        { "Author": "Sample Text" },
        { "Author" : "Second Sample Text" }
    ]

Response:
    Status: 201 Created
Content-Type:
    application/json
Body:
{
    "Result": [
        {
            "Id": "f71a37d0-b8ff-11e5-981b-99782870ba17",
            "CreatedAt": "2016-01-12T07:42:00.653Z"
        },
        {
            "Id": "f71a5ee0-b8ff-11e5-981b-99782870ba17",
            "CreatedAt": "2016-01-12T07:42:00.654Z"
        }
    ]
}
var multiple = [{ "Author": "Sample Text" }, { "Author": "Second Sample Text" }];

$.ajax({
    type: "POST",
    url: 'http://api.everlive.com/v1/your-app-id/type-name',
    headers: { "Authorization": "Bearer your-access-token" },
    contentType: "application/json",
    data: JSON.stringify(multiple),
    success: function (data) {
        alert(JSON.stringify(data));
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
})

See Also