Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

jira assets import examples

DPWC Licensing
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 21, 2023

Hello all,

I'm migrating from JIRA Server to JIRA Cloud. I'm a heavy user of JIRA Assets, and I need to import objects from on-premise CSV files to the cloud instance daily. I've reached to the "generate token" part in the external import option, but I don't have a clue of how I can use this token or how can I configure the token with a Python script. Is there any tutorial or example of this?

Thanks in advance.

2 answers

0 votes
Paolo Bolla March 10, 2023

Hello, i've tried the entire process and seems to be ok. You can use the token as Bearer Auth. 

With postman:

  • GET /imports/info to get getStatus, start and mapping link and saving link on postman workspace variables (Tests section on request):
    var jsonData = JSON.parse(responseBody);
    pm.collectionVariables.set("getStatus", jsonData.links.getStatus);
    pm.collectionVariables.set("start", jsonData.links.start);
    pm.collectionVariables.set("mapping", jsonData.links.mapping);
  • PUT {{mapping}} to set the schema
  • (optional) PATCH /{{mapping}} with ONLY the object to be modified and only the fields to be added or modified following the guide
  • POST {{start}} to start the import and get all the links (saved again in variables)
    var jsonData = JSON.parse(responseBody);
    pm.collectionVariables.set("submitProgress", jsonData.links.submitProgress);
    pm.collectionVariables.set("submitResults", jsonData.links.submitResults);
    pm.collectionVariables.set("getExecutionStatus", jsonData.links.getExecutionStatus);
    pm.collectionVariables.set("cancel", jsonData.links.cancel);
  • POST {{submitResults}} with JSON with { "data": { "obj1": [], "obj2": [] .....}
  • POST {{submitResult}} with payload {"completed": true}
  • (optional) GET {{getExecutionStatus}} to monitor the completion of the import

The reason of "Conflict" is that you cannot PUT on existing schema

Paolo 

Chris C. March 10, 2023

Yeah I figured out PUT wouldn't work to re-write the mapping. But PATCH doesn't fix it back to the way it was supposed to be either. Once Assets forgets an object type mapping the only way to get it back is to delete the type mapping from the Import console completely, then do the PATCH. 

Also, this is not true:
PATCH /{{mapping}} with ONLY the object to be modified and only the fields to be added or modified following the guide

Once I delete the one object type mapping (1 of 5), PATCH does in fact accept the mapping for everything. I had to do this for all of my importers. So I added some code to my lambda function to cram the mapping down Asset's throat on EVERY CALL.  It hasn't forgotten what it's supposed to be doing again. Just check the results every so 

Paolo Bolla March 10, 2023

Hi Chris, i've used the PATCH to modify following the https://developer.atlassian.com/cloud/assets/imports-rest-api-guide/schema-and-mapping/#supported-operations page. So only certain operation is permitted.

To make certain changes I too had to cancel some data not only from import console but even from the objects if created. 

It's not the best way to manage the import and could have been done better.

Like Chris C. likes this
Chris C. March 10, 2023

Definitely agree with that last point.

0 votes
Chris C. March 1, 2023

I've been struggling with this for months. I found these two articles somewhat helpful:
https://developer.atlassian.com/cloud/assets/imports-rest-api-guide/schema-and-mapping/
https://developer.atlassian.com/cloud/assets/imports-rest-api-guide/workflow/

I also use a chrome plugin (Vivaldi browser) called RestMan, it's really helpful in stepping through the process before you start writing out the python, so you can see which returned URLs you're supposed to ask for. Once you have an external importer created in Assets, it will give you the token that you need to use in the headers like this:

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer xxTOKENxx'
}

I'm using urllib3 to make the HTTP requests.

Basically works like this, in your Python (or RestMan) call GET on the info URL to get the next set. Then GET the status URL, it should respond with missing mapping. You then send PUT to the mapping URL with the JSON mapping, check the Assets importer afterwards to see if they're right. When you GET the info URL again, it should respond IDLE. If it does, then you're ready to start the process of sending the data package of your objects. I'm building my JSON document in AWS Lambda with one script, then sending that object over to another module I wrote to handle the connections and sending. I don't know if the external importer can accept a CSV file, you might have to convert it to JSON document. You have the option of sending the data in chunks then sending a completed signal when done. In my case I built the JSON document beforehand (package), so I can include the completed signal with the object data like this:

chunk = {"data": {},"completed": True}
chunk['data'].update(package)

Very confusingly  what I've figured out is, you have to call POST to the start URL in order to activate the importer, only then can you send the objects by calling POST to submitResults URL. If the completed True signal is included in the chunk, or sent separately, the GET to getStatus URL will return IDLE again. If it doesn't go back to IDLE, you'll probably have to use the cancel URL and start over. I had to cancel mine numerous times due to the confusing and marginally ambiguous documentation provided.

 

The problem I'm having currently is, Assets decided to forget the mapping for one of my five object types. This occurred on all five of my external importers too. So all of my storage, security and network objects are being updated correctly, but NONE of my servers are being updated for 2 days now. Which is massively frustrating. Documentation says I should be able to update the mapping by sending a PATCH to the mapping URL, but this doesn't do anything, like at all. It does not care. It responds with status code 204, but doesn't update anything. If I try to PUT it again like you do in the beginning, you get an error like this:
{
"timestamp": "2023-03-01T00:00:00.000+00:00",
"status": 409,
"error": "Conflict",
"path": "/rest/insight/1.0/importsource/stuff-goes-here/mapping"
}

 

This has been the most irritatingly difficult process I've dealt with in years. Support has not been helpful at any step along the way. I honestly don't think they understand any of this either. If you get stuck where I'm stuck and manage to figure it out, please report back. 

Best of luck!

Paolo Bolla March 10, 2023

See below.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events