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

2 posts, 0 answers
  1. eaxe
    eaxe avatar
    3 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post


    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.
  2. Ivan Pelovski
    Admin
    Ivan Pelovski avatar
    16 posts

    Posted 29 Aug 2013 Link to this post

    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.
Back to Top