Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bash, cURL, and creating new projects

Raynard Rhodes
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.
August 14, 2020

I'm in the process of automating creating a JIRA project. I noticed when I use this cURL command from within a bash script I receive this error

Error:

{"errorMessages":[],"errors":{"projectKey":"Project keys must start with an uppercase letter, followed by one or more uppercase alphanumeric characters."}}

 Command:

curl -u username -X POST https://jirainstance/rest/project-templates/1.0/createshared/${project_id} -H "Content-type: application/json" --data '{"key":"${Project_key^^}", "name":"${project_name}", "lead":"${project_lead}"}'

This only shows up when I use a variable in place of the key data. If I use this command with directly typing in the key data it works normally. Any ideas?

2 answers

1 accepted

0 votes
Answer accepted
Raynard Rhodes
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.
August 17, 2020

I had to encase the --data information in double quotes and escape the double quotes within it.

According to this link, variables are not expanded in singe quotes

https://stackoverflow.com/questions/40852784/how-can-i-use-a-variable-in-curl-call-within-bash-script

Raynard Rhodes
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.
August 17, 2020

curl -u username -X POST https://jirainstance/rest/project-templates/1.0/createshared/projectID -H "Content-type: application/json" --data "{\"key\":\"${newprojectname}\", \"name\":\"Double Quote Test\", \"lead\":\"username\"}"

0 votes
Prince Nyeche
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.
August 14, 2020

Hi @Raynard Rhodes 

The error says must start with uppercase, so are you actually using uppercase letters in the project key that is being fed into the command? variable substitution wouldn't really matter here. As long as the data being received and sent to the endpoint is correct, Jira will process the request and output a response.

Raynard Rhodes
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.
August 17, 2020

Thank you for your response. 

I've tried using both upper and lowercase. Even still, I added ^^ to ensure the variables value will be all caps.

echo "Project Key"
read Project_key
echo ${Project_key^^}

is what I use and then pass Project_key to cURL.

Raynard Rhodes
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.
August 17, 2020

I just ran a test to see if it was the variable and it seems that it is being taken literally.

curl -u username -X POST https://jirainstance/rest/project-templates/1.0/createshared/projectID -H "Content-type: application/json" --data '{"key":"BEST", "name":"${newprojectname}", "lead":"username"}'


I have the same echo/read commands prior to this curl command. 

The project is created, but the name is "${newprojectname}" and not what is stored in the variable.

Prince Nyeche
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.
August 17, 2020

okay, i think the data is not formatted properly.

curl -u username -X POST https://jirainstance/rest/project-templates/1.0/createshared/projectID -H "Content-type: application/json" --data '{"key":"BEST", "name":"'${newprojectname}'", "lead":"username"}'

you should add single quotes to the variable substitution, so it can actually detect it. Also when writing curl it's better to use an editor such as atom.io it will give you syntax highlight, so you can know what's wrong. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events