Updating Data Items

Updating Data Items

Using a Backend Services RESTful API call you can update a single item based on its ID or multiple items based on a filter expression.

Updating a Single Item by ID

You need to know the item's ID to update it. Then include it in the request URL right after the content type name.

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

Response:
    Status: 200 OK
Content-Type:
    application/json
Body:
    {
        "ModifiedAt": "2016-01-12T08:13:36.176Z",
        "Result": 1
    }
var object = {
    "Author" : "Updated value"
};
$.ajax({
    type: "PUT",
    url: 'https://api.everlive.com/v1/your-app-id/type-name/item-id',
    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));
    }
})

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

Updating Multiple Items

Multiple items are typically updated trough a filter but you can also omit it in which case you will be updating all items in the content type.

Always double-check your filter expression and test it on a dummy copy of your data. This will help you avoid overwriting the wrong items.

The following example updates all items that contain a Author field valued "Sample Text". On success, the response contains the number of updated items.

Request:
    PUT https://api.everlive.com/v1/your-app-id/type-name
Header:
    Authorization Bearer your-access-token
X-Everlive-Filter
    { "Author" : "Sample Text" }
Body:
    { "Author" : "Updated Sample Text" }

Response:
    Status: 200 OK
Content-Type:
    application/json
Body:
    {
        "ModifiedAt": "2016-01-12T08:20:40.958Z",
        "Result": 3
    }
var filter = {
    "Author":"Sample Text"
};
var object = {
    "Author": "Updated Sample Text"
};

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

Be careful when updating fields marked as unique (IsUnique) by filter as it may match multiple items. In this case, Telerik Platform updates the first matching item if the update value does not duplicate an existing item, after which it stops executing the request and returns an error. The rest of the matching items are not updated.

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.