How to set the description to a given patchset in gerrit - rest

I want to set the description to a given patchset in Gerrit with the official REST API.
When I execute the command following, Gerrit Authentication is required.
My curl is this:
curl -u userName:password -X PUT
-H "Content-Type: application/json"
-d '{"description": "test message"}'
http://gerritServer:port/changes/project~master~changeId/revisions/revisionId/description
I have added the Gerrit authentication, why do I still need authentication?

Related

Github api request returning bad credentials even with admin privledged oauth token

I am trying to make a call https://api.github.com/repos/OWNER/REPO/actions/runners/registration-token with an users personal access token that has repo permissions.
To do so I am testing with:
curl -I -X POST -H "Authorization: token <OAUTH_TOKEN> Accept: application/vnd.github.v3+json" https://api.github.com/repos/<owner>/<repo-name>/actions/runners/registration-token which gives me Bad Credentials error
curl -I -H "Authorization: token <OAUTH_TOKEN>" https://api.github.com/users/<USER_NAME> ->
x-oauth-scopes: repo
x-accepted-oauth-scopes:
According to this: https://docs.github.com/en/rest/actions/self-hosted-runners I need to provide an oauth token with repo access.
If I curl the user curl -H "Authorization: token <OAUTH_REPO_TOKEN>" https://api.github.com/users/<USER>/repos -> []. But if I go to the repo and check settings -> Collaborators And Teams, the user is listed as part of the team with admin privledges, and I have also added an entry for the user directly.
Is there something I am missing? What permissions do I need to add to fix this?
I needed to call the API with a user name as well. For example:
curl -I -X POST -u <USER>:<OAUTH_REPO_TOKEN> -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/<owner>/<repo-name>/actions/runners/registration-token. Passing a -v option reveals that it was not setting a username, and causing github to reject the call.

How to assemble preemptive auth in curl command , while using POST method

I need to use POST method for a REST API.It's working perfectly in SOAP UI while i select "Preemptive Authentication" , I need to assemble this authentication option in Curl.
At Web service , preemptive properties has not set. It has only Basic authentication system with username & password.
I have tried --anyauth , it's not working. I have below command.
curl -X POST -H "content-type:application/json" --verbose -u username:password http://example.net:1234/api/Flows/UpdateStatus -d '{"EventId": "123","Status": "success"}'
I am always getting below error.
{"Message":"Authorization has been denied for this request."}
I had tried with providing base64 encoded value of user & password at header section instead of providing user & password under user section ,and it got worked for me.
curl -X POST -H "content-type:application/json" --verbose -H "Authorization: Basic Base64_encoded_value_of_user_&_password" http://example.net:1234/api/Flows/UpdateStatus -d '{"EventId": "123","Status": "success"}'

Getting 400: Bitbucket API command to grant Access on Branch

I am trying to automate the process to provide the user access on Bitbucket branches on the cloud via bitbucket API using curl command. Please help me with the command as I have visit link. But no luck.
I have run the below command but getting 400. Please help where I am doing the wrong.
.\curl -i -u user:password -H "Content-Type: application/json" -X POST -d '{"type": "no-delet
es","matcher": {"id": "refs/heads/branchname","displayId": "branchname","type": {"id": "BRANCH","name": "Bra
nch"},"active": true},"users": ["user"],"groups": []}' 'https://api.bitbucket.org/rest/branch-permissions/2.0/pro
jects/projectkey/repos/reponame/restrictions'

Upload SSH public key to bitbucket cloud using curl/REST and token

I have a bitbucket cloud account. Under: https://id.atlassian.com/manage/api-tokens I have generated an API Token which I am trying to use in a REST call to upload
a public SSH key to my account. Based on:
https://docs.atlassian.com/bitbucket-server/rest/5.6.2/bitbucket-ssh-rest.html?utm_source=%2Fstatic%2Frest%2Fbitbucket-server%2F5.6.2%2Fbitbucket-ssh-rest.html&utm_medium=301#idm45427244388592
https://community.atlassian.com/t5/Answers-Developer-Questions/Bitbucket-REST-API-POST-using-token-instead-of-basic-auth/qaq-p/474823
I have tried:
curl -X POST -d '{"text":"ssh-rsa AAAAB3... me#127.0.0.1"}' -H "Authorization: Bearer ADasdaEeasAsd..." https://bitbucket.org/[my-account]]/rest/ssh/latest/keys
But when I run that I get:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
I have tried to re-create the token and re-run the above command again - with the new token - but I get the same error.
Any suggestions?
Based on below answer and link I have now tried:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wxdrtblabla..." \
-d '{"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY myuser#bitbucket.org/myuser"}' \
https://api.bitbucket.org/2.0/users/myuser/ssh-keys
But I get the exact same error:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
So still no luck. Also if I access:
https://api.bitbucket.org/2.0/users/[myuser]/ssh-keys
directly in a browser I get:
type "error"
error
message "This API is only accessible with the following authentication types: session, password, apppassword"
EDIT/ANSWERED: Based on the updated answer below I have no tried to create an app password and grant it account: read/write in bitbucket and it works. I run it with:
curl -v -u myuser:my-generated-app-password -X POST \
-H "Content-Type: application/json" \
-d '{"key": "ssh-rsa AAA....ro"}' \
https://api.bitbucket.org/2.0/users/myuser/ssh-keys
You're looking at Bitbucket Server documentation but using Bitbucket Cloud. (The giveaways: the "bitbucket-server" part of the doc path, and the "bitbucket.org" in the path where you're pushing your key.)
Check out https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D/ssh-keys#post instead - that's the Bitbucket Cloud documentation to do what you're trying to do. Your URL will be more like https://api.bitbucket.org/2.0/users/[your-account]/ssh-keys.
EDIT: The error you received indicates the problem: you either need to make that call from within an existing session (i.e. from the GUI), use your password, or use an app password. I'd recommend the app password, since it's scoped, meant to be disposable, and won't let you log onto the GUI. Your curl call then becomes something like curl -u myuser:myapppassword -X POST -H "Content-Type: application/json" -d '{"key": "key content goes here"}' https://api.bitbucket.org/2.0/users/myuser/ssh-keys.

Need an example for Add User to Group function in JIRA REST API 6.1

I am developing an application that uses the JIRA 6.1 REST API. Can I know a sample JSON Object that I should use, to add a user to a given group in JIRA?
This is the relevant API call: https://docs.atlassian.com/jira/REST/latest/#d2e1694
curl -D- -u admin:password -X POST --data "{\"name\": \"charlie\",\"password\": \"abracadabra\",\"emailAddress\": \"charlie#atlassian.com\",\"displayName\": \"Charlie of Atlassian\"}" -H "Content-Type: application/json" http://jira.server.com/rest/api/2/user/
For more info see. Expand part under application/json, there you can find data example.
How to send queries, refer to Atlassian's documentation.
Came across this thread while looking to do the exact same thing. The answer from #ThePavolC was very good, but it is creating a new user, not adding a user to a group. I combined his answer with info from https://answers.atlassian.com/questions/255778 and came up with this one-liner:
curl --insecure -D- -u admin:password -X POST --data "{\"name\": \"username\"}" -H "Content-Type: application/json" https://myjiraserver.com/rest/api/2/group/user?groupname=mygroupname
Replace password" with the actual admin password.
Replace username" with the name of the user you're adding to the
group.
Replace myjiraserver.com with your JIRA server's FQDN.
Replace mygroupname with the name of the group to which you are
adding this user.
I added the --insecure option because of the private SSL certs used on my server. You may not need that, or you may not be using HTTPS at all (in which case edit the URL to use HTTP).