Data360 DQ+ can leverage its REST API node to connect to various endpoints, such as Jira. This example will focus solely on creating Jira tickets via REST API; however, any other Jira action that supports REST API can be used too.
Jira Authorization
This section assumes you already have a Jira account with the appropriate permissions to read and write tickets.
These instructions will cover Basic authorization. You can opt for Oauth authorization in place of the steps below.
The Jira REST APIs require authorization with a username and password. However, the password is not your standard password to log into Jira. The password is an API Token that can created via Atlassian's Manage API Tokens web page.
You'll need reformat your username and password into the standard base64 format to use Basic authorization. Once you have your token, open a terminal window and run the following command to encode your username and passwords as base64:
echo -n yourusername:yourtoken | base64
Save the output value for later use. This value will be used for your REST API authorization.
Note: You must use the -n flag in order for the encoding to process correctly. Otherwise the echo command will add a newline character and alter the base64 encoding.
Creating the create issue API payload
In this example, a hard-coded JSON payload is set by JavaScript since the focus of this article is primarily connecting to Jira. For more details on how to systemically create JSON, check out our How to create JSON in DQ+ article.
The script below is used within a JavaScript node to hard-code the JSON payload.
output.payload = '{ "fields": { "summary": "Sample ticket created from DQ+", "description": "No action is required on this ticket.", "project": { "id": "10007" }, "reporter": { "id": "5b3a257624f7612e7d4b3eb9" }, "issuetype": { "id": "10008" } } }';
emitRecord();
To add more Jira ticket fields, including custom fields, please review Atlassian's documentation.
The output of this node will be used as the input into the REST API node:
The formatted version of the JSON payload is below:
{
"fields": {
"summary": "Sample ticket created from DQ+",
"description": "No action is required on this ticket.",
"project": {
"id": "10007"
},
"reporter": {
"id": "5b3a257624f7612e7d4b3eb9"
},
"issuetype": {
"id": "10008"
}
}
}
Connecting to Jira with REST API node
This section will assume that you have some familiarity with the REST API node. More details about the REST API node can be found in our Using the REST API node article.
- Within the REST API node properties, set the URL property using the following syntax:
https://<your jira instance>/rest/api/2/issue
- Set the HTTP method to POST and leave Authentication as None. Authorization will be handled via a header.
- A sample of the completed settings within the Request tab is below:
- In the Request Header tab, set the Authorization property using the following syntax:
Basic <base64 value>
This base64 value is the same value from the echo command used earlier in this article. For example, if your base64 value was 1234567890, your Authorization header would be set to:Basic 1234567890
- Set Content-type to application/json
- A sample of the completed settings within the Request Headers tab is below:
- In the Request Body tab, set the Body property using the following syntax:
${<payload variable name>}
For example, if your payload is stored in a field named "payload", the body value will be:${payload}
- In the Response tab, set each of the field names to unique names. These will be the names of the output fields from the API call:
- When running the REST API node, you should receive a value of 201 in your status field. This is the HTTP code indicating the API call to create a ticket was successful.
The issue in Jira will contain the summary, description and any other field defined in your payload:
Comments
0 comments
Please sign in to leave a comment.