Jira REST API adding user to groupname with spaces

I'm needing to convert one of our old soap scripts to rest, for adding new users to specific groups.

This is basically a bash script that uses curl to post to the endpoint.

The problem is that many of our groups have space in the names (eg "MyCompany Retail") and somewhere this is being ignored.

I've tried replacing the spaces in the string with either a + or %20, but these seem to be ignored, claiming the user is already part of "MyCompany".

Is such a thing possible?..

 

Thanks,

Sean

1 answer

This widget could not be displayed.
Mikael Sandberg Community Champion Oct 02, 2017

Try using "%26", that is what I was using in my ruby script when I needed to rename groups in JIRA.

if group.include? "&"
group = group.sub!("&", "%26")
end

As you can see below (sorry that it's a bit untidy, I copied something we were using for another function) I ended up using %20 as it was replacing spaces.
I thought it wasn't working as the 'previously existing' return code check returns a 1 instead of a 0, but (if you ignore the last if statement shown below) it does actually work as I can see the group membership changing in the admin interface.


GROUP_NAME=${GROUPNAME/\ /\%20}

# create json formated output to send it
generate_post_data(){
cat <<EOF
{
"name": "$USER_NAME"
}
EOF
}


# send user create request to JIRA
create_result=$(curl -H \
-D- \
-sS \
-u $JIRA_ADMIN_USER:$JIRA_ADMIN_PASSWORD \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST "$JIRA_URL/rest/api/2/group/user?groupname=$GROUP_NAME" \
--data "$(generate_post_data)" \
)

echo $create_result | grep -q "\"name\":\"$USER_NAME\""

if [ $? -eq 0 ]; then
echo "User ($USER_NAME) added to $GROUPNAME."
exit 0
else
echo "ERROR: user NOT added to group!"
echo $create_result
exit 1
fi

 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 18 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

45 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you