Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira copy project component to another project component using Python

Gian Israel Nampi
Contributor
August 25, 2020

Hi,

I need to move (A) Project components to (B) Project Components, I can do this manually or via script runner, but I wanted to use it via rest api, I am currently using this script atlassian-api / atlassian-python-api

I have specified the correct project source key of source and destination but I got Status 400 Bad request from https://url_here/rest/api/2/component. What is the correct rest api for the component? I can get the status from rest/api/2/project/key/components but not in https://url_here/rest/api/2/component. Do you have any recommendation to fix this problem? Thanks in advanced!

Jira version: v8.5.4 Jira Project Management Software

# coding=utf-8
from atlassian import Jira
import logging

logging.basicConfig(level=logging.ERROR)

jira = Jira(
url="https://url_here/",
username="username",
password="password")

DST_PROJECT = jira.get_project_components(key='PROJECT_B')
SRC_PROJECT = jira.get_project_components(key='PROJECT_A')
components = jira.get_project_components(key='SRC_PROJECT')

for component in components:
data = {"project": DST_PROJECT,
"description": component.get('description'),
"leadUserName": component.get('leadUserName'),
"name": component.get('name'),
"assigneeType": component.get('assigneeType')
}
jira.create_component(data)
print("{} - component created ".format(component.get('name')))

 

2 answers

1 accepted

0 votes
Answer accepted
Gian Israel Nampi
Contributor
September 1, 2020

Hello,

This is now resolved, I fixed it by Installing PyCharm and used it instead of IntelliJ IDEA and Visual Studio Code. I then use same script from the Atlassian-Python-API and it proceeds to copying and creating the components.

Thank you.

0 votes
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 26, 2020

Hello @Gian Israel Nampi

Thank you for reaching out.

Can you confirm if you are using Jira Server or Cloud application?

I ask this question because your REST API format is on the Server format, however, your support tier is selected as Jira Cloud, which would use a different format for the REST CALL:

https://url_here//rest/api/3/component/{id}

Additionally, I believe the best place to ask for help about scripting would be in our Atlassian Developer Community:

https://community.developer.atlassian.com/ 

The mentioned portal was specifically created for development questions, where you will find articles and suggestions from other third-party partners and Atlassian developers. Feel free to open a new topic about your question there! :)

Let us know if you have any other questions.

Gian Israel Nampi
Contributor
August 28, 2020

Hi @Petter Gonçalves

 

I have created new Topic at https://community.developer.atlassian.com/ 

Copy component to another component Topic 

 

I am using Jira Server, the errors I got is.

  1. jira.create_component(data)
  2. return self.post(url, data=component)
  3. response = self.request(‘POST’, path=path, data=data, headers=headers, files=files,
    params=params,
    response.raise_for_status()
  4. requests.exceptions.HTTPError: 400 Client Error: for url: https://my_url.com/rest/api/2/component

Base on the Jira API Components link below

 https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/component

rest/api2/component - its using "POST" so it creates a component with the following. Did I missed something?

{

    "name": "Component 1",

    "description": "This is a JIRA component",

    "leadUserName": "fred", "assigneeType":

    "PROJECT_LEAD", "isAssigneeTypeValid": false,

    "project": "PROJECTKEY", "projectId": 10000

}

Thank you.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events