Managing Cloud Code Programmatically

Managing Cloud Code Programmatically

The Backend Services RESTful API includes a set of endpoints for administratively managing Cloud Code for Data. All require Master Key authentication.

Reading Cloud Code for a Certain Content Type

To get the cloud code associated with a certain content type you need the Id of the type and pass it in the URL, followed by "/Code".

//Ajax request using jQuery
$.ajax({
    url: "https://api.everlive.com/v1/Metadata/Applications/your-app-id/Types/type-id/Code",
    type: "GET",
    headers: {"Authorization" : "Masterkey your-master-key"},
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    GET https://api.everlive.com/v1/Metadata/Applications/your-app-id/Types/type-id/Code
Headers:
    Authorization  Masterkey your-master-key
Response:
    Status: 200 OK
    Content-Type: application/json

Setting Cloud Code

You can set your cloud code by encoding the file in base64 format and passing the result in the requests body.

//Ajax request using jQuery 
var object = {
    "Filename":"myCloudCode.txt",
    "ContentType":"text/plain",
    "base64": "RXZlcmxpdmUuRXZlbnRzLmJlZm9yZVJlYWQoZnVuY3Rpb24ocmVxdWVzdCwgY29udGV4dCkgew0KICANCn0pOw=="
};

$.ajax({
    url: 'https://api.everlive.com/v1/Metadata/Applications/your-app-id/Types/type-id/Code',
    type: "PUT",
    headers: {"Authorization" : "Masterkey your-master-key"},
    data: JSON.stringify(object),
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    PUT https://api.everlive.com/v1/Metadata/Applications/your-app-id/Types/type-id/Code
Headers:
    Authorization  Masterkey your-master-key
Payload - raw:
    {
        "Filename":"myCloudCode.txt",
        "ContentType":"text/plain",
        "base64": "RXZlcmxpdmUuRXZlbnRzLmJlZm9yZVJlYWQoZnVuY3Rpb24ocmVxdWVzdCwgY29udGV4dCkgew0KICANCn0pOw=="
    },
Response:
    Status: 200 OK
    Content-Type: application/json

Deleting Cloud Code

Deleting the code and setting it back to the default can be done with a request like this below.

//Ajax request using jQuery 
$.ajax({
    url: 'https://api.everlive.com/v1/Metadata/Applications/your-app-id/Types/type-id/Code',
    type: "DELETE",
    headers: {"Authorization" : "Masterkey your-master-key"},
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    DELETE https://api.everlive.com/v1/Metadata/Applications/your-app-id/Types/type-id/Code
Headers:
    Authorization  Masterkey your-master-key
Response:
    Status: 200 OK
    Content-Type: application/json
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.