We are trying to create Jira ticket from Jira REST API. We are reading data from file and that contents we are trying to pass to description field in Jira. Our file contains multiple lines and because of this it is not working.
We suspect that this is not working because of multi line in description field.
curl -D- -k -u user:pwd -X POST --data '{"fields": {"project": {"key": "KOSPN"},"summary": "NOCAutomation-EnvName-Issue","description": "'"$(cat /root/ZK/lle/final.txt)"'","issuetype": {"name": "'$Issuetype'"},"customfield_16103": {"value": "'$env'"},"customfield_13700": {"value": "'$level'"},"customfield_16102": {"value": "'$Domain'"},"customfield_11506": {"value": "'$release'"},"customfield_11805": {"value": "'"$RequestType"'"},"customfield_12300": {"value": "'"$project"'"},"customfield_21305": {"value": "'$No'"},"customfield_11804": [{"value": "'$Component'"}]}}' -H "Content-Type: application/json" https://jiradc.test.com:8443/rest/api/2/issue
Contents of /root/ZK/lle/final.txt which is used as input to description field
QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)
QA02 cncservice SNB_SERVICE_HOST actual value (10.208.99.9) is not matching with expected value (10.208.9.12)
QA02 cncservice XYZ_SERVICE_HOST actual value (10.208.4.118) is not matching with expected value (10.208.9.3)
Error: When i execute the script in debug mode below is what is constructed for CURL command here the description field contains multiple lines hence ticket is not getting created
curl -D- -k -u user:passwd -X POST --data '{"fields": {"project": {"key": "KOSPN"},"summary": "NOCAutomation-EnvName-Issue","description": "QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)
QA02 cncservice SNB_SERVICE_HOST actual value (10.208.99.9) is not matching with expected value (10.208.9.12)
QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)","issuetype": {"name": "Task"},"customfield_16103": {"value": "QA02"},"customfield_13700": {"value": "L1"},"customfield_16102": {"value": "ACT"},"customfield_11506": {"value": "Backlog"},"customfield_11805": {"value": "Environment Issues"},"customfield_12300": {"value": "2018 VGC"},"customfield_21305": {"value": "Yes"},"customfield_11804": [{"value": "accservices"}]}}' -H 'Content-Type: application/json' https://jiradc.test.com:8443/rest/api/2/issue
Response is:
HTTP/1.1 400
X-AREQUESTID: 327x44020628x4
X-ANODEID: pl001367
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-ASEN: SEN-4259792
Set-Cookie: JSESSIONID=30FA54033D0AA6EFA9716EA5C9E69AED;path=/;Secure;HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=BOOQ-GGIW-E4RQ-BKG0|119aa3a9b6cd1c35ddacddaf0f8dad1cfd798c26|lin;path=/;Secure
X-ASESSIONID: 1ez4fp1
X-AUSERNAME: TKMADNI
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 08 Aug 2018 10:27:21 GMT
Connection: close
{"errorMessages":["Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@64531914; line: 1, column: 208]"]}+
Hey, Prateek. Thanks for reaching out to the Atlassian Community.
It seems the issue is that the '\n' newline character is not accepted, you need to escape it with another backslash('\').
You can use the following commands to replace the newline character with the literal "\n":
cat ~/final.txt | sed 's/$/\\n/g' | tr -d '\n'
Other simpler option is to just save the file with the literal '\n' instead of actually making a newline(pressing return). Here's the example:
QA02 cncservice ACM_SERVICE_HOST actual value (10.208.4.18) is not matching with expected value (10.208.9.21)\nQA02 cncservice SNB_SERVICE_HOST actual value (10.208.99.9) is not matching with expected value (10.208.9.12)\nQA02 cncservice XYZ_SERVICE_HOST actual value (10.208.4.118) is not matching with expected value (10.208.9.3)
Kind regards,
Maurício Karas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.