This is a migrated thread and some comments may be shown as answers.

How to trigger Everlive CloudCode, when insert data to other tables.

1 Answer 58 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
eaxe
Top achievements
Rank 1
eaxe asked on 29 Aug 2013, 10:21 AM

Everlive.Events.beforeDelete(function(request, context, done) {
  var options = {
        headers: {"Authorization" : "Masterkey RZ8XA9MVj0wRYbf8Hiwxn********"},
        data: {"tableid":request.data.Id} 
    };
  
    Everlive.Http.request('POST', 'https://api.everlive.com/v1/2Mc4knjbXD*******/deletes/', options,
        function(error, response) {
            if(error){
                //Do something with the error here
            } else {
                //Do something with the response here
            }                
            
        }
    );
done();
});

No error, but not work.

1 Answer, 1 is accepted

Sort by
0
Ivan Pelovski
Telerik team
answered on 29 Aug 2013, 02:24 PM
Hi,

There are some problems with the code you use:
  • The Id of the deleted item is placed in 'request.itemId' field. You should get it from there.
  • You should not use a 'data' field for passing data for a POST request. You should use the 'body' field. You can read more about this at the Cloud Code section of the Everlive documentation.
  • You should set the content type of the request. In your case it should be 'application/json'.
  • The 'done()' function should be invoked inside of the 'request' callback. Check the sample code inside of the documentation.

Here is what your code should look like:

Everlive.Events.beforeDelete(function(request, context, done) {
  var options = {
        headers: {"Authorization" : "masterkey ..."},
        body: {"tableid":request.itemId},
        contentType: "application/json"
    };
   
    Everlive.Http.request('POST', 'https://api.everlive.com/v1/.../deletes/', options,
        function(error, response) {
            if(error){
                //Do something with the error here
            } else {
                //Do something with the response here
            }                           
            done();
        }
    );
});


Regards,
Ivan Pelovski
Telerik

Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
Tags
General Discussion
Asked by
eaxe
Top achievements
Rank 1
Answers by
Ivan Pelovski
Telerik team
Share this question
or