cURL command failed to delete pull-request from bit bucket with 400 error - rest

I am trying to delete a pull-request from bitbucket. I am using the following command,
curl -v -u {username}:{password} -X DELETE -H "Content-Type:application/json" https://{bitbucket.com}/rest/api/1.0/projects/{project_name}/repos/{repo_name}/pull-requests/{pull-request_id}
but the command fails with an error code 400. Please find the error:
{"errors":[{"context":null,"message":"No content to map to Object due to end of input","exceptionName":"java.io.EOFException"}]}.
I think I am missing something in the rest url. Please help me to resolve the issue. Thanks in advance

You need to pass the "version" of the pull-request (remember that the pull-request version starts in 0). Add the "-d #-" option to send the version in a here-document.
curl -v -u {username}:{password} -d #- -X DELETE -H "Content-Type:application/json" https://{bitbucket.com}/rest/api/1.0/projects/{project_name}/repos/{repo_name}/pull-requests/{pull-request_id} <<EOF
{
"version": {version}
}
EOF

Related

CircleCI job is failing, help troubleshoot

PUBLIC_DNS=$(aws ec2 describe-instances --region ${AWS_DEFAULT_REGION} --filters 'Name=tag:Name,Values=udapeople-backend-ec2-*' --query "Reservations[*].Instances[0].PublicDnsName" --output text)
echo ${PUBLIC_DNS}
curl -H "Content-Type: text/plain" \
-H "token: ${CIRCLE_WORKFLOW_ID}" \
--request PUT \
--data ${PUBLIC_DNS} \
https://api.memstash.io/values/public_dns
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
Exited with code exit status 2
CircleCI received exit code 2
your error isn't with Circle CI but with your curl command. The error message is saying it doesn't have a URL to which to PUT. I do see that you included a URL in your curl command, so maybe the problem is in your line endings. Try removing the line endings and run your circle CI job again. You can also try running the command from your local command line.
This is because memstash.io is not working as a website or webservice, there is no issue in your code , memstash is working as a memory-cache for CD jobs so you can find another CD caching service or you have a good option to use circle ci caching itself , try to search for circleCI docs

Can't download using Nexus 3 REST API and CURL

I'm trying to download the latest snapshot dependency of a zip on Nexus 3 (version 3.22.1-02) from a command line using curl:
curl -u username:password -X GET "https://mynexusserver/service/rest/v1/search/assets/download?sort=version&repository=snapshotsrepo&maven.groupId=mygroup&maven.artefactId=myartefact&maven.extension=zip" -H "accept: application/json" -o myartefact.zip
This request is similar to this example: http://help.sonatype.com/repomanager3/rest-and-integration-api/search-api#SearchAPI-DownloadingtheLatestVersionofanAsset but no result is returned, myartefact.zip is empty.
However with the same URL, my artefact is downloaded from a web browser or with gradle.
With curl the following command line is working fine, returning the list of all snapshot versions of my artefact:
curl -u username:password -X GET "https://mynexusserver/service/rest/v1/search/assets?sort=version&repository=snapshotsrepo&maven.groupId=mygroup&maven.artefactId=myartefact&maven.extension=zip" -H "accept: application/json" -o myartefact.zip
Downloading the artefact directly is working fine as well with a command line like:
curl -u username:password "https://mynexusserver/repository/snapshotsrepo/mygroup/batchfactory/myversion-SNAPSHOT/myartefact-myversion-mytimestamp.zip" -H "accept: application/json" -o myartefact.zip
Verbose logs (-v option) show the artefact is found (I get HTTP/1.1 302 Found message) but nothing is downloaded.
Using wget doesn't work any better, I can't even query the list of snapshot version of the artefact.
Am I missing something?
Thanks #Zeitounator, after adding "-L" the command line works fine. Considering code 302 this feels obvious now...
Nexus documentation should also probably be updated to add the "-L" option.

Create Bitbucket Pull Request Comment via REST

I want to create a bitbucket comment after finishing my bamboo build. Unfortunately my rest call didnt work. ALso Im getting no response.
Am I missing something?
curl -u "USER:PASSWORD" -X POST -d '{"body": "Your Message to Comment"}' "http://URL/2.0/repositories/OWNER/REPO/pullrequests/ID/comments"
Execute the following command:
curl -u "USER:PASSWORD" --request POST --data '{"text": "YOUR-COMMENT"}' "BITBUCKET-SERVER/rest/api/1.0/projects/PROJECT/repos/REPO/pullrequests/ID/comments"

curl no URL specified error, even though URL is being specified

I'm attempting to execute the following CURL call via commandline:
curl -i -H "Content-Type:application/json" \
-u "m19389#dev.acp.co.com:qE2P/N7y1k.\(" \
-X GET -d "https://wefd.it.co.com:3905/events/com.co.mpm.dev.29160-wgdhfgd-v1/dsd/dsdfds-0-0-1-7c49768976-2g7kq"
I've added quotes around the arguments and all, and I'm definitely inclusing the curl url, so I'm not sure what's going on here. Where did I go wrong?

Atlassian Confluence : Updating parent container of an attachment

I'd like to move an attachment to a different space (i.e, update the parent container of an attachment in a Confluence page) using Cloud REST API and "curl" command. I looked up REST API endpoint URL and found this:
PUT /rest/api/content/{id}/child/attachment/{attachmentId}
Could somebody provide an example for a correctly constructed JSON input to achieve this? I tried the one below to move an attachment called "test.jpeg" with ID "att000" and current version 5 to parent with ID 1234, but it fails:
curl -v -u 'admin:password' -X PUT -H 'Content-Type:application/json' -d '{"id":"att000","type":"attachment","title":"test.jpeg","version":{"number":5,"minorEdit":false},"ancestors":[{"id":1234}]' -H ‘X-Atlassian-Token:access-token' https://test.atlassian.net/wiki/rest/api/content/170234/child/attachment | python -m json.tool
Given below is the error message
< HTTP/1.1 415 Unsupported Media Type
.
.
.
No JSON object could be decoded
Thank you for your time!
I believe in your curl example you are uploading it under space which is not possible. Attachments in Confluence needs to be under content. Take a look at following example:
curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=#myfile.txt" -F "comment=this is my file" "http://localhost:8080/confluence/rest/api/content/3604482/child/attachment" | python -mjson.tool
You have to set the container property in the request object.
Specify "container":{"id":"123456","type":"attachment"}
curl -v -u 'admin:password' -X PUT -H 'Content-Type:application/json' -d '{"id":"att000","type":"attachment","title":"test.jpeg","version":{"number":5,"minorEdit":false},"container":{"id":"123456","type":"attachment"}, "ancestors":[{"id":1234}]' -H ‘X-Atlassian-Token:access-token' https://test.atlassian.net/wiki/rest/api/content/170234/child/attachment | python -m json.tool
id => id of the page where attachment is being moved.