Insert, Update and Delete JIRA Issue in SQL Server

Introduction

UPDATE: ZappySys has released a brand new API Connector for Jira Online which makes it much simpler to Read/Write Jira Data in ODBC compared to the steps listed in this article. You can still use steps from this article but if you are new to API or want to avoid learning curve with API then use newer approach.

Please visit this page to see all Pre-Configured ready to use API connectors which you can use in SSIS API Source / SSIS API Destination OR API ODBC Driver (for non-SSIS Apps such as Excel, Power BI, Informatica).

Write in JIRAIn our previous blog we saw how to read JIRA data in SQL Server. In this blog, we will learn how to Insert, Update and Delete Issue in JIRA using ZappySys JSON Driver. We will also read data from SQL Server data table in stored-procedure and insert JIRA issues in bulk, along with few other topics such as how to generate an API Token using Atlassian Account for JIRA REST API Call, how to update and delete Issue data in JIRA using REST API calls.

So, let’s get started.

Requirements

  1. A first requirement will be to SQL Server Database Engine Installed
  2. The second requirement will be SSMS installed
  3. Finally, make sure to have ZappySys ODBC PowerPack installed.

What is JIRA

JIRA is Atlassian’s popular project- and issue-tracking platform used by development and technical support teams to get more work done and faster.

It combines:

issue tracking – a software application that allows to record and follow the progress of every problem or “issue” that user identifies until the problem is resolved.
agile project management – an iterative approach to planning and guiding project processes. customizable workflow, and a pluggable integration – integrates with Freshdesk, GitHub, Zendesk, Zapbook, Asana and so on.

Getting Started

First of all, we will see several examples. ZappySys includes an ODBC JSON Source Connector that will help you to call JIRA API, Insert issue in JIRA using static data from the SQL server using ODBC JSON driver REST API Call. Update and Delete JIRA issue data From the SQL Server. Insert Bulk JIRA issues from the stored procedure. To learn more about JIRA API check this help file.

Generate API Token

To access JIRA data using REST API call you need to generate an API Token in your Atlassian account. Follow the steps mentioned below to generate API Token:
  1. you can directly login to the JIRA Atlassian Cloud site with your credentials, and redirect to the JIRA Atlassian Cloud Account's Profile Page for generating an API Token.
  2. Click API tokens, then Create API token.
    Generate API Token - Step - 1

    Generate API Token - Step - 1

  3. Create API Token - Give Label name to your API token which you are generating now
    Generate API Token - Step - 2

    Generate API Token - Step - 2

  4. Use Copy to the clipboard, and paste the token into your or elsewhere:
    Note:  * For security reasons it isn't possible to view the token after closing the creation dialog; if necessary, create a new token. * You should store the token securely, just as for any password.
    Generate API Token - Step - 3

    Generate API Token - Step - 3

  5. If you forgot API token, then you can Revoke your old API token and create new API token OR you can create multiple API tokens too.
    Generate API token - Step - 4

    Generate API token - Step - 4

Now we have successfully generated an API token. Let´s start with an example. In this example, we will show how to read Tasks/Issues data from JIRA and store that data into a SQL table with SSIS.

About JIRA REST API

JIRA On-premises and Cloud Version both offers REST API. Here are some examples of JIRA REST API. For inserting issue in JIRA we will use JIRA REST API create issue method. We can also insert issues in bulk using Create issues bulk method. To update issue we will use this PUT method: Updating an Issue via the JIRA REST APIs. To delete issue we will use this DELETE method. You can find JIRA Rest API example on this link: Jira REST API examples

Step-by-Step: Write in JIRA from SQL Server

Now once you have API token in the JIRA Atlassian Cloud website we can move to ODBC JSON Driver Configuration Part. For this example purpose you can use the following URL:

hence, your-domain is your Atlassian Cloud account’s domain name (we are using zappysys2.atlassian.net).

Above all, each API endpoint may have a different limit for the number of items returned, and these limits may change without notice. (For more See this JIRA REST API reference)

Configure ZappySys Gateway data Source for JIRA

  1. To do this, first of all, we will open the ZappySys Data Gateway Configuration:
    Open ZappySys Data Gateway

    Open ZappySys Data Gateway

  2. Add the Native – ZappySys JSON Driver Data source.
    Add Gateway Data Source (Native JSON Driver)

    Add Gateway Data Source (Native JSON Driver)

  3. Now it’s time to connect with JIRA. Let’s use JSON Driver Data source with the following URL:
    ODBC JSON Driver: Enter Request URL

    ODBC JSON Driver: Enter Request URL

  4. It is time to configure the Other Settings. Select HTTP Connection Type from the Connection Type drop-down and Click on Click to Configure Link to Configure the Connection Manager.
    JIRA REST API Connection - Use ZappySys JSON Driver HTTP Connection

    JIRA REST API Connection – Use ZappySys JSON Driver HTTP Connection

  5. Now, Let’s Add request body input data of issue.
    odbc-Issue Input Data

    Issue Input Data

  6. Now using Query Builder we will generate the query.
    ODBC-json-generate-query

    Generate JIRA Rest API Post Method Query

  7. Now Let’s Test Connection and it will prompt the message “Connection is OK!”
  8. That’s it we have successfully configured JIRA Rest API in ODBC JSON Driver.

Setup Linked Server in MS SQL Server for JIRA

Once you configured the data source in Gateway, we can now setup Linked Server in SQL Server to query API Calls.

  1. Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: Get SQL Server Express and  Get SSMS
  2. Open SSMS and connect to SQL Server.
  3. Go to Root > Server Objects > Linked Servers node. Right click and click New Linked Server…

    Add Linked Server in SQL Server

    Add Linked Server in SQL Server

  4.  Now enter the linked server name, select Provider as SQL Native Client
  5. Enter data source as  GatewayServerName, PORT_NUMBER where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway > General tab in case its different.
  6. Enter Catalog Name. This must match name from Data gateway Data sources grid > Name column

    Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection

    Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection

  7. Click on Security Tab and select last option “Be made using this security context“. Enter your gateway user account here.
  8. Click OK to save Linked Server

Insert data in JIRA from SQL Server (Call POST API Method)

  1. To Insert the issue in JIRA we need to execute the query like this. Please refer to this link for more information: Creating an issue example.
    Important Note*: If you don’t pass META='{xxxx}’ in query driver call REST API 2 times first time to parse metadata and second time to get actual data. So that you find some odd thing in JIRA project if you execute the query without Meta then you will find two same issues created in your JIRA project as the driver makes two calls as mentioned above.
  2. Here is the preview after you run REST API query in SQL Server. It will return created issue id, key, and Link. Now let’s note down this response to update and delete the same issue if you want to. Notice that you can override default configuration by supplying many parameters in WITH clause.
    odbc-insert-issue-in-jira

    Insert Issue In JIRA Using SQL Query

  3. You can also find this created issue in your JIRA project.
    jira-issue-preview-in-browser

    Created Issue in JIRA

Update data in JIRA from SQL Server (Call PUT API Method)

  1. Let’s update the issue which we created in the previous step using id. I Added Extra Meta details in Query to prevent driver to make two calls and also to prevent error as JIRA Rest API Response is a blank Status code of "204 No Content". Please refer to this link for more information: Updating an Issue via the JIRA REST APIs
  2. Let’s is the preview after you running update query in SQL Server.
    odbc-update-jira-issue

    Update Jira Issue From SQL Server

  3. Now, Let’s see the updated issue in JIRA project.
    https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira.png

    Updated Issue In JIRA Project

  4. One Import note if you don’t add that metadata then you will get an error like below as JIRA Rest API Response is a blank “Status code of ‘204 No Content'”. If you don’t set META the REST API Make Two calls First to parse metadata and for the second time to get actual data.
    Query execution error: No data returned for specified table name or filter expression. Make sure table name or filter is typed correctly (it is case sensitive) and input data contains a corresponding element(s).

Delete data in JIRA from SQL Server (Call DELETE API Method)

  1. Now let’s delete the issue which we created by executing following query in SQL Server. We also need to add extra meta details in query same as update one as JIRA Rest API Response is a blank Status code of "204 No Content". Please refer to this link for more information: Delete an Issue via the JIRA REST API
  2. Now, Let’s check the deleted issue in JIRA project.
    deleted-issue-in-jira

    Issue Deleted in JIRA Project

Create multiple JIRA issues using SQL Server Stored Proc

Now lets put all previous things to more practical use. We will create a stored procedure which will read Issues stored in a SQL Table and Submit it to JIRA to create new Issue via REST API call. This will make it totally dynamic so SQL Table can act as your Source of information for API call.

  1. Let’s create stored procedure to read data from “tblIssues” data table and create bulk issues in JIRA.
  2. That’s it now executes the stored procedure and you will find bulk issues created in your JIRA project.
    Bulk Issues Created In Jira

    Bulk Issues Created In Jira

Conclusion

In this blog, we learned how to generate a JIRA API Token and how to configure it,  Insert, Update and delete Issue in JIRA using ODBC JSON / REST API Driver from the SQL server. You can achieve many more functionalities with this tool. Check our blogs/articles on JSON / REST API Driver to find out what this tool is capable of more.

References

Finally, you can use the following links for more information about the use of JIRA API with our tools:

Posted in JSON File / REST API Driver, ODBC Gateway, ODBC PowerPack, REST API, T-SQL (SQL Server) and tagged , , , .