kintone.api for Thread Comments

So I’ve recently been working on creating some sample code using the kintone REST API Request , Add Thread Comment API and the Record Create Event.

What I wanted to do, was to post comments into a space thread every time a new record is added into an app.

I tried to do this with the below code, but can’t seem to debug the error that comes up. The error comes up for a tiny bit in the console, but since the event is run when I’m adding records, the error only stays in the console for a split second before the page changes, and the consol refreshes.

I can’t seem to find what’s wrong though :frowning:

 

(function() {
    “use strict”;
    kintone.events.on(“app.record.create.submit”, function(e) {
        var user = kintone.getLoginUser().name;
        var commentbody =   {
                                “space”: 11,
                                “thread”: 17,
                                “comment”: {
                                    “text”: user + " posted the following: “” + e.record.titletext.value +"""
                                }
                            }

        kintone.api(’/k/v1/space/thread/comment.json’, ‘POST’, commentbody);
       
    });
})();

 

Hello Akira!

Have you tried using the breakpoint to debug the error?

Hi Yuzo

Sorry I took some time here looking up how to do breakpoints.
I set some breakpoints up, but I couldn’t get the page to stop when the error showed up.

What I managed to do instead though was to add the callbacks that were listed
in the kintone REST API Request samples so I ended up with something like this

(function() {
    “use strict”;
    kintone.events.on(“app.record.create.submit”, function(e) {
        var user = kintone.getLoginUser().name;
       
        //The function called on success
        var callback = function(event){
            alert(“It worked!”);
        }
    
        //The function called on error
        var opt_errback = function(event){
            var errmsg = ‘There was an error when retrieving the data’;    
            if (event.message !== undefined){
                errmsg += ‘’ + event.message;
            }
            alert(errmsg);
        }
       
        var commentbody =   {
                                “space”: 11,
                                “thread”: 17,
                                “comment”: {
                                    “text”: user + " posted the following: “” + e.record.titletext.value +"""
                                }
                            }

        kintone.api(’/k/v1/space/thread/comment.json’, ‘POST’, commentbody, callback, opt_errback);
       
    });
})();

It then gave me an alert box when the error came up in the console.

I could’t click into the error (probably because the alert dialogue was showing)
but I did notice something fishy with the URL saying .json.json

That’s where I notice I was posting this:

kintone.api(’/k/v1/space/thread/comment. json’ , ‘POST’, commentbody, callback, opt_errback);

instead of this:

kintone.api(’/k/v1/space/thread/comment’, ‘POST’, commentbody, callback, opt_errback);

 

Bad URL stated in the request. My bad. Problem is fixed now though, thanks!