Use rest api with jquery to run a deploy?
Asked by David Shapiro:

Hello,

I am looking for enough information on how to create a web page to run a deploy that is scheduled. I was able to cobble together something that shows the projectId, environmentId, and versionId list (release numbers), and even a calendar to let users pick a date and time, but I am having trouble actually submitting a form that will do something with the information. I tried $.ajax for example:

```
First off, authentication is a mystery.?However, it would be best if it used an auth token.  All I see out there is how to create tokens for Jira or Confluence, but nothing for Bamboo.  The steps do not work.        ?I think as long as I am logged in to bamboo, no other authentication, and I am guessing if a user were to us this, they would need to have deploy permission to the project.  Yes, yes, why not just use Bamboo (sigh).  This has to do with wanting to use some product called servicenow, so that product will need to run "Something" to do the work for the user.?I still do not know what rest api call is used to include a scheduled time.  I tried to simply run a deploy. Note I tried jsonp to deal with cors, but if you have the magic to get this working, I would love to hear it (application link?  what do you fill in if you have to set that up and where/how do you get the info to setup an application link?:  ?     var url = "https://mydomain.com/bamboo/rest/api/latest/queue/deployment/";             url += "?environmentId=" + $('#environment').val();             url += "&amp;versionId=" + $('#release').val();                console.log(url);                alert(url);                $.ajax({                        type: 'POST',                        url: url,                        data: "",                        dataType: 'jsonp',                        async: 'false',                        success: function() {                                alert("POSTED");                        },                        error: function() { alert("failed!"); }                });        }Whatever I do it will either run and show no error (no alert box pops up), but it will not run deploy, or it will throw:?XMLHttpRequest cannot load https://esapps.sas.com/bamboo/rest/api/latest/queue/deployment/?environmentId=95158277&amp;versionId=94470491?os_authType=basic. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://favorites.unx.sas.com' is therefore not allowed access. The response had HTTP status code 401.I see there is a whitelist option in Bamboo, but it does not let me do anything with it and it does not seem to be REST API related (maybe just for java or plugins).?With jsonp sometimes it says:?Refused to execute script from 'https://esapps.sas.com/bamboo/rest/api/latest/queue/deployment/?environment?e=basic&amp;callback=jQuery110208378970937783805_1485533032763&amp;_=1485533032764' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.?I am praying somebody can give enough information to do the following:1. setup token authentication2. use the token with jquery $.ajax call to run the deployment3. show me what i need to tack onto the url to also include a schedule for the trigger event.
```


Answers:
author: roy_lyons
body: Personally, I would just have the jquery send to a webservice (hosted somewhere, maybe even on the bamboo box itself) and have the webservice perform the magic, and return the information back to the jquery call.


Tags: bamboo-administration