简体   繁体   中英

How to print a text file using curl to jira api

I am using curl command on linux server to create a jira ticket with certain subject and description using JIRA API. Now I want to print the Description of jira with the content of a file say test.txt, but I am unable to achieve this. It is always printing the actual command which I use to print the file ie cat test.txt, below is the command

curl -k -D- -u username:password -X POST --data '{"fields":{"project":{"key": "BD"},"summary": "CRITICAL - '"This is the subject part"'","description": "'$(cat text.txt)'","issuetype": {"name": "Support - Other"}}}' -H "Content-Type: application/json" -s "https://jiradc.kohls.com:8443/rest/api/2/issue" 

Please let me know the workable solution

To create an issue using the Jira REST API using file , follow these steps:

1.) Create the data file that contains the POST data. For this example, we'll assume the file is named data.txt.

2.) Add the following JSON to the file:

{
    "fields": {
       "project":
       {
          "id": "10000"
       },
       "summary": "No REST for the Wicked.",
       "description": "Creating of an issue using ids for projects and issue types using the REST API",
       "issuetype": {
          "id": "3"
       }
   }
}

In this data, the project ID is 10000 and the issue type in our case is 3, which represents a task. You should pick an ID of a project in your instance and whichever issue type you prefer.

Note that instead of the id you can also use the key and name for the project and issuetype respectively. For example,"key": "TEST" for the project and "name": "Task" for the issuetype.

3.) In Terminal window, run the following command:

 curl -u admin:admin -X POST --data @data.txt -H "Content-Type: application/json" http://localhost:8080/jira/rest/api/2/issue/

As before, adjust details for your environment, such as the hostname or port of the Jira instance. Note that a cloud instance or most public instances would require the use of HTTPS and, of course, valid credentials for the instance.

4.) When your issue is created, check the response that will look something like this:

{
   "id":"10009",
   "key":"TEST-10",
    "self":"http://localhost:8080/jira/rest/api/2/issue/10009"
} 

JIRA REST API Examples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM