How to trigger build from JavaScript (REST API)

Hello,

I'm trying to trigger a build from JavaScript. When I try the following code, I get "400 (Bad Request)"

            var data = {
                buildType: {id: buildTypeId}
            }

            console.info(data);
               
            $.ajax({
                method:"POST",
                url:buildQueueUrl,
                data:data,
                dataType: "json",
                contentType: "application/json",
                success: function(){console.log(data);}
            });


Am I doing something wrong? "buildQueueUrl" has the value of "/httpAuth/app/rest/buildQueue"

2 comments
Comment actions Permalink

I was supposed to pass "jsonp" instead of "json" to dataType. I changed the code and tried it out, but I got the same result.

0
Comment actions Permalink

Hi Hayato,

jsonp is not supported, only application.xml and application/json are.
I'd recommend getting the right request with a sinple tool like curl or some other request sender and then making sure JavaScript code sends the same request.
Examples, though with XML can be found in the doc.

0

Please sign in to leave a comment.