Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

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 https://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: 'https://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));
    }
})

Normally, you don't need to specify the item ID—a GUID will be generated for you. However, if you need to set a specific ID, such as when importing existing data from an external database, you can do that by simply passing it with the request. Your custom ID must meet the following conditions:

  • Must be unique inside the application
  • Must be a string
Body:
    {
        "Id" : "008541a0-b38a-11e5-84b2-b9c8b2734ef4"
        "Author" : "Sample value"
    }

You can update system fields such as CreatedAt and CreatedBy. However, you can set them only after doing the following:

Creating Multiple Items

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

Request:
    POST https://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: 'https://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));
    }
})

Telerik Platform verifies fields marked as unique (IsUnique) just before creating each item. It keeps creating items until it reaches a duplicate value, after which it stops executing the request and returns an error. The rest of the items are not processed.

See Also

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