Missed Team ’24? Catch up on announcements here.

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

How to add change history (statusses) through csv or rest api

Jeroen Van Bortel December 10, 2012

We are migrating data from an old issuetracker to Jira (through the csv importer). I was able to map every field, even multiple comments and attachments for the same issue.

The one thing that we were not able to map were the status changes.

I can set the (final) status of the issue but want to keep track of all the status changes.

As far as I can see, Jira keeps track of these status changes in the form of changelog history items.

I can get the existing ones through REST by querying them like this ../rest/api/2/issue/PROJECT-73?expand=changelog

Output is something like this:

"changelog":{

  • "startAt":0,
  • "maxResults":1,
  • "total":1,
  • "histories":[
    1. {
      • "id":"27737",
      • "author":{
        • "self":"http://x.x.eu/jira/rest/api/2/user?username=x",
        • "name":"x",
        • "emailAddress":"x.x@x.eu",
        • "avatarUrls":{
          • "16x16":"http://x.x.eu/jira/secure/useravatar?size=small&ownerId=x&avatarId=10401",
          • "48x48":"http://x.x.eu/jira/secure/useravatar?ownerId=x&avatarId=10401"
          },
        • "displayName":"x x",
        • "active":true
        },
      • "created":"2012-11-27T17:01:49.750+0100",
      • "items":[
        1. {
          • "field":"status",
          • "fieldtype":"jira",
          • "from":"1",
          • "fromString":"Open",
          • "to":"10003",
          • "toString":"Waiting for internal input"
          }
        ]
      }
    ]

}

Naturally, these statusses are bound to the workflow attached to the project.

Now, my question is:

- Can I insert these entries with the CSV importer? Just like comments and attachments?

- Or if not, can I add them with the REST API doing a POST or PUT command?

And it would be nice to have an example of this.

Thanks!

Jeroen

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Pawel Niewiadomski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2012

It's not a problem as you think. Just put a column in the CSV file that would be unique for each issue, then during the wizard map it to Issue Id field, it will get copied to External System Id custom field. So then you will now which issue id was imported to what issue key. You can dump it and use to create JSON file.

Jeroen Van Bortel December 11, 2012

Hi Pawel,

So I would then be able to map the JSON file to this "External System Id" custom field without having to mention the actual jira id in the JSON? So basically I would mention the "External System Id" and my historical status changes. Thats it?

Jeroen

Pawel Niewiadomski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2012

No, you can't do that. If importer notices the same External Issue Id it will skip the issue.

You still have to map issues and write issue key in JSON file.

Or if you really want to have it your way (and use issue id) you can modify the importer so it will not skip issue with the same External Issue Id but it will update it. Should be rather simple but I think the first option is simpler.

Getting a matching pair of External Issue Id and Issue Key should be as simple as running Issue Navigator and exporting the results.

Jeroen Van Bortel December 11, 2012

Hi Pawel,

Ok, I will give it a go.

Thanks

Jeroen

Jeroen Van Bortel December 11, 2012

Hi Pawel,

I'm currently trying to add history to an issue. But the JSON imports fails saying:

2012-12-12 16:51:15,715 ERROR - Failed to create data bean
java.lang.RuntimeException: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "key" (Class com.atlassian.jira.plugins.importer.sample.SampleData), not marked as ignorable
 at [Source: java.io.StringReader@eacecdf; line: 21, column: 2] (through reference chain: com.atlassian.jira.plugins.importer.sample.SampleData["key"])

The JSON that I try to upload looks like this:

{

  • "expand":"changelog",
  • "key":"YTMIG-217",
  • "changelog":{
    • "histories":[
      1. {
        • "author":{
          • "name":"dclaes"
          },
        • "created":"2012-11-27T17:01:49.750+0100",
        • "items":[
          1. {
            • "field":"status",
            • "fieldtype":"jira",
            • "fromString":"Open",
            • "toString":"Waiting for internal input"
            }
          ]
        }
      ]
    }

}

Can you tell me whats wrong with this JSON?

Thanks

Jeroen

Pawel Niewiadomski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2012

This file is in incorrect format. Please oberve in the documentation that you need to have an object that has "projects" key first, then an array of objects that represent projects, then for each project's object you need to have "issues" key, which has a value that's an array that lists objects that will be imported as issues.

Jeroen Van Bortel December 16, 2012

Hi Pawel,

Thanks for your answers. I haven't had the chance to test it yet. But I'll do so this week and keep you posted.

Thanks

Jeroen

1 vote
Pawel Niewiadomski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2012

So, you are not able to use CSV importer to import them.

You can't import change history items using JIRA REST - you can change issue status, but you can not force the data to be in the past.

You can use JIRA Importers Plugin to achieve what you want, but you need to use JSON (beta) format, and the good news is that you can just update issues (so you can keep the work you did with CSV).

Here's a documentation and there's an example of an issue with some historical status changes - https://confluence.atlassian.com/pages/viewpage.action?pageId=293830712

Mind you the dates are in silly joda format, but you can use normal date format as weel, the example uses relative dates (which are kinda coll for some purposes).

Jeroen Van Bortel December 11, 2012

Hi Pawel,

That seems like a cool import tool. But it would give me a lot of work because I first have to import all issues through CSV, then need to export them into JSON format. Then update the different issues in JSON format to have all the historical status changes, and finalmly reimport them into JIRA to actually import these status changes.

I cannot automate this so easy.

That leaves me thinking, maybe we can do it in another way.

To import a comment via CSV importer, you can just enter multiple entries in the csv with the same header and then map them to the comment field in Jira.

How about creating a custom field which can do the same for my historical statusses?

Is it possible to create a custom field, for instance (Old Issuetracker Statusses), which is a collection of a date, username, oldstatus, newstatus?

Ultimate goal would be to have multiple columns in the CSV import with the header "Old Issuetracker Statusses" and map them to the custom collection field "Old Issuetracker Statusses" in Jira. The notation in the CSV would then be the same as for comments. An entry would be something like this "12/12/2012 23:00:12;jvanbortel;Open;Closed".

Can this be done fairly easy?

Thanks

Jeroen

Pawel Niewiadomski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2012

Actually you don't have to do the whole round-trip as you described. All you need to do is import issues using CSV, prepare a simple JSON file that would list only each issue key as created in JIRA and have for each issue history set. Then those issues that are in JIRA will be updated with the information from JSON file. Yeah, that's enough :-)

To comment your idea - sure you could create a custom field but you'd have to code all the logic into it and the parsing. I believe it's a lot of coding and the result may vary.

I advise you to try out JSON importer, just run a test with one issue and see how it goes.

Jeroen Van Bortel December 11, 2012

Hi Pawel,

If such a special field needs to be coded, then you are right, the JSON would be the better option.

Though it would still present a lot of work. Why? ... wel...

Our CSV is generated through code. It does not now which JIRA Id it will get when it is imported. So I cannot automate the JSON file togheter with the CSV.

I would somehow have to list all the jira issue-id's of the imported CSV issues and then, for all these issues compile a JSON file. If I want to automate this, the export of my old issuetracking system would have to know which Jira Id is coupled to which own issue id. And it doesn't know about this. So automation of these JSON files is difficult if not impossible.

Since we are talking about 1800 issues, you can catch my drift.

So, de you have any ideas on how we can automate the generation of these JSON files? I guess, through the CSV import, you cannot force the issue to have a certain Jira Id? If that would be possible, then I could generate the JSON togheter with my CSV file since I know which Jira Id it is going to get when imported.

Thanks

Jeroen

Pawel Niewiadomski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 1, 2013

If each issue imported from CSV has set a column that is mapped to Issue ID the value will be placed in a custom field called External System ID so you will not lose the track between CSV issues and JIRA keys.

You can then dump this information from JIRA and use it to produce JSON file.

TAGS
AUG Leaders

Atlassian Community Events