Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Why my cURL call to tag a repository doesn't work?

Martin Schemel August 10, 2015

information I am using Stash 3.11.1 and curl-7.33.0-win64 

According to https://developer.atlassian.com/static/rest/stash/3.11.0/stash-scm-git-rest.html it's possible to tag remote repositories via ReST API.

So I tried. My cURL call looks as follows:

curl -u myuser:mypassword -H "Content-Type: application/json" -X POST -d '{"force":"true","message":"test-msg","name":"test-name","startPoint":"refs/heads/master","type":"ANNOTATED"}' http://stash.mycompany.int:7990/projects/SAMPLE/repos/sample/tags

 

What I retrieve is some HTML text which shows the navigation menu (projects, repositores, etc.). But there's also a headline "Oops, you've found a dead link". Is this ReST API still up to date? I think it was introduced with 3.8 and not public so it MIGHT have changed. Checking in Stash UI: There is no new tag :/

Any ideas?  (Tell me if you need more information).

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Felix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 10, 2015

Hi @Martin Schemel,

it looks like the URL you are specifying in your curl call is not correct. 

The following command should work:

curl -u myuser:mypassword -H "Content-Type: application/json" -X POST -d '{"force":"true","message":"test-msg","name":"test-name","startPoint":"refs/heads/master","type":"ANNOTATED"}' http://stash.mycompany.int:7990/rest/git/1.0/projects/SAMPLE/repos/sample/tags

Note the "/rest/git/1.0/" in the url.

I hope that helps, 

Felix

0 votes
Martin Schemel August 10, 2015

At first, thank you for that quick response, @Felix Haehnel!

Now I notice that this "/rest/git/1.0/" path is documented on the page I just posted. Sorry for that.

This seems to solve at least this concrete problem. So I corrected the URL. Now the URL seems to be correct but I get the following response:

{"errors":[{"context":null,"message":"Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@740c2ac6; line: 1, column: 2]","exceptionName":"org.codehaus.jackson.JsonParseException"}]}

So it seems that my JSON format is corrupt.

It seems that on the one hand a context needs to be specified (how/what?) and on the other hand the message contains an invalid ' sign? I already tried to remove the - sign from the message which did not help.

Any ideas again? smile


Update / solution: 

Seems to be a OS related problem. When I call

-d "{\"force\": \"true\",\"message\": \"A new release tag\",\"name\": \"release-tag2\",\"startPoint\": \"refs/heads/master\",\"type\": \"ANNOTATED\"}"

instead of 

-d '{"force": "true","message": "A new release tag","name": "release-tag2","startPoint": "refs/heads/master","type": "ANNOTATED"}'

it works. So basically I have to escape the inner quotation marks.

information I'm using Windows 7 64bit.

 

Felix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 10, 2015

I just tried the command as I posted it in my answer on Stash 3.10.2 (Windows, using curl in Cygwin) - it worked for me. I would suggest you try saving the JSON to a file and referencing that in your curl command. For example: curl -u myuser:mypassword -H "Content-Type: application/json" -X POST -d @myfile.json http://stash.mycompany.int:7990/rest/git/1.0/projects/SAMPLE/repos/sample/tags

Martin Schemel August 10, 2015

Yep with a file it works fine. You helped me a lot. Thank you!

Rashmi May 1, 2019

Hi Felix, How to store user input to json file?

I am trying to create bitbucket project using below curl command:

curl -X POST -H "Content-type: application/json" --basic --user $username:$password https://abc.com/bitbucket/rest/api/1.0/projects -d '{"key": '$projectname', "name": '$projectname', "description": '$projectname'}'

TAGS
AUG Leaders

Atlassian Community Events