I have Created a addon button in the view issue screen using Webitemn ,Now on clicking this Button the issue must create as a Jira project, Using the rest api,kindly answer in this case
@SarikaWelcome to the community!
You can use Javascript and call Jira's Rest API using 'web-resource-module' by adding it to view-issue page context, and listing to click event of your button.
You can learn about Web Resource Module here - https://developer.atlassian.com/server/jira/platform/web-resource/
This is my web resource and webitem
<web-resource key="JiraPluginbutton-resources" name="JiraPluginbutton Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="JiraPluginbutton.css" location="/css/JiraPluginbutton.css"/>
<resource type="download" name="JiraPluginbutton.js" location="/js/JiraPluginbutton.js"/>
<resource type="download" name="images/" location="/images"/>
<context>atl.general</context>
<context>atl.admin</context>
<context>jira.view.issue</context>
<context>jira.userprofile</context>
</web-resource>
<web-item name="JiraProject" i18n-name-key="jira-project.name" key="jira-project" section="operations-top-level" weight="1">
<description key="jira-project.description">The JiraProject Plugin</description>
<label key="jira-project.label"></label>
<link linkId="jira-project-link"/>
</web-item>
</atlassian-plugin>
This is my Java Script file
JiraPluginbutton.js
AJS.$(document).ready(function() {
AJS.toInit(function() {
AJS.$('#jira-project-link').click(function(e) {
e.preventDefault();
alert("A new jira project gets created ")
});
});
});
As i am very new to Atlassian SDk, here where i need to call rest api
inside the javaScript
and where to set the location view-issue page context
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@SarikaYou are on right track,
Simply call API using various functions provided by '$' i.e. JQuery. For example,
AJS.toInit(function () {
var API_BASE_URL = contextPath + "rest/api/2";
AJS.$("#integration-button-link").click(function(eve) {
eve.preventDefault();
//Get projects list
AJS.$.getJSON(API_BASE_URL + "/project", function(data) {
console.log(data);
});
//Create new project
var data = JSON.stringify({
"key": "SAM",
"name": "Sample Project"
// Add more params as defined in API reference
});
AJS.$.ajax({
url: API_BASE_URL + "/project",
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: data,
success: function (response) {
console.log(response);
}
});
return false;
});
});
API reference for creating project - https://docs.atlassian.com/software/jira/docs/api/REST/8.5.3/#api/2/project-createProject
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AJS.toInit(function () {
var API_BASE_URL = http://localhost:2990/jira + "rest/api/2";
AJS.$("#jira-project-link").click(function(eve) {
eve.preventDefault();
//Get projects list
AJS.$.getJSON(API_BASE_URL + "/project/13502", function(data) {
console.log(data);
});
//Create new project
var data = JSON.stringify({
"id":"1102",
"key": "SAM",
"name": "Sample Project"
// Add more params as defined in API reference
});
AJS.$.ajax({
url: API_BASE_URL + "/project",
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: data,
success: function (response) {
console.log(response);
}
});
return false;
});
});
I get no error but the Project doesnot created ,Can you please help in this case
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please add,
'failure': function (response) {
console.log(response);
}
to your ajax request. To see what is missing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.