We are trying to rename Job of Jenkins using its REST API, in-spite of using correct REST Endpoint we get status code as 302 Found when using CURL. Postman works fine.
curl -v -X POST <jenkins_url>/job/<old_job_name>/doRename?newName=cr%20test -H 'Authorization: Basic E45tg646YWRtaW4tryu=' -H 'Cache-Control: no-cache' -H 'Jenkins-Crumb: <CSRF token>'
Status code when tested using CURL: HTTP/1.1 302 Found
As per this https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html, status code 302 means The requested resource resides temporarily under a different URI.
This is the issue with every Jenkins REST API.
It looks like in every Jenkins REST request there are two call made over HTTP/HTTPS the first call make appropriate changes are per request and second call confirms whether requested changes are made.
Important Note - Though it gives 302 status code, in background it serves the purpose. If my above statement is right then here it is failing at second call that confirm whether changes made.
Please suggest how would I resolve this issue.
Related
I have a script that I'd like to be able to access via a curl command against its https://raw.githubusercontent.com/... location. Using git.io, it's really easy to shorten this URL to something like https://git.io/ABCDE.
But there's an issue related to the fact that my script exists in a private repository. If I directly curl against the githubusercontent URL, I get 404: Not Found. I'm able to bypass this by passing an authorization header with the request, e.g.
$ curl -H "Authorization: token <My Github Personal Access Token>" \
https://raw.githubusercontent.com/...
> !#/bin/bash
... # rest of script
However, when I use my shortened URL, I don't get anything back. Not even a 404.
$ curl -H "Authorization: token <My Github Personal Access Token>" \
https://git.io/ABCDE
$
Anyone know what's going on here?
The way a URL shortener works is that it issues some sort of 3xx-series HTTP status code that redirects you to the new location, and then you make your request against that new location. However, by default, curl does not follow redirects, so all you see when you make your request is the output from git.io, which in this case is nothing.
If you want to follow redirects, then you should use the -L option to curl, which will make it follow redirects. Note that this can be insecure in many cases when passing credentials, since any credentials passed with -H will be passed to any remote server that the data is redirected to. In this case, that's what you want, but it can be a security problem in other cases if the credentials were only intended for the original server.
I'm trying to send a POST request to the GitHub API to submit a comment on a commit.
According to the documentation, all that's needed (other than the URL params) is the body.
I have modified the example from the docs to the following:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/dchacke/test/commits/9b7413350932dd3f2906c0fdd26106c35c7ce450/comments \
-d '{"body":"test comment"}'
That should post a test comment to this commit. I know the commit and the owner and repo exist (it's my repo and I can see the commit under that URL), and yet I'm getting a 404 with the following response body upon submitting that API request:
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-commit-comment"
}
The documentation makes no mention of authentication being required for that endpoint. A 404 doesn't exactly sound like an authentication problem, but just in case GitHub doesn't want to confirm the existence of repos/commits to unauthenticated users (though they do let them see those things on their website...), I tried setting a personal access token in an additional Authorization header in my CURL request. No dice.
What am I doing wrong?
Authentication was the issue after all. I had to make sure I used a token with the right privileges. In this case, it needed the public_repo privilege, which can be set up here.
REST: POST fails with CSRF enabled, though it works in POSTMAN.
I have added several headers like -H Set Cookie: JSESSIONID=xxxx along with -H X-CSRF-TOKEN: bbbb, -b cookies.txt after generating it. I would like to know what exactly has to be added to make the request work ?
I'm trying to use the relatively new PayPal Sync API to download my PayPal transactions. I'm following the Sync API guide. I started by logging into the PayPal Developer Dashboard My Apps & Credentials page, scrolling to the REST API apps section, creating an app, clicking on it, and enabling Transaction Search for both the Sandbox and Live accounts.
I then used the Sandbox account's Client ID and Secret to generate an Access Token. I confirmed that the Client ID and Secret are correct and active. My cURL command is below (note that I'm using cURL on Windows 10):
curl -v https://api.sandbox.paypal.com/v1/oauth2/token ^
-H "Accept: application/json" ^
-H "Accept-Language: en_US" ^
-u "<my-client-id>:<my-secret>" ^
-d "grant_type=client_credentials"
I received a response similar to the following (I added the formatting):
{
"scope":"https://uri.paypal.com/services/reporting/search/read
https://api.paypal.com/v1/payments/.*
https://uri.paypal.com/services/applications/webhooks
openid",
"nonce":"2018-04-04T02:20:02Z...",
"access_token":"<my-access-token>",
"token_type":"Bearer",
"app_id":"<my-app-id>",
"expires_in":32400
}
I then took the Access Token and copied it into the sample command on the Sync API guide page. Here is the command I ran:
curl -v -X GET https://api.sandbox.paypal.com/v1/reporting/transactions?transaction_id=5TY05013RG002845M&fields=all&page_size=100&page=1 ^
-H "Content-Type: application/json" ^
-H "Authorization: Bearer <my-access-token>"
I received the following error response:
< HTTP/1.1 401 Unauthorized
...
< Content-Length: 244
< Connection: close
< Content-Type: application/json
<
{
"name":"AUTHENTICATION_FAILURE",
"message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.",
"links":[{
"href":"https://developer.paypal.com/docs/api/overview/#error",
"rel":"information_link"
}]
}
I tried many things to correct this error, including:
Adding a "Accept: application/json" and "Accept-Language: en_US" header to the command.
Creating a new Secret and generating a new Access Token.
Creating a new App with a new Client ID & Secret and generating a new Access Token.
Disabling Transaction Search, re-enabling it, and sending the command again.
Trying in the Live account.
Each of these attempts produced the same result. I noted that in the scope section of the access token response that it doesn't include a path similar to the stated path for the Sync API (/v1/reporting/transactions). However, that's just an observation, and I'm not sure if that is relevant.
I read through the entire Sync API guides and documentation about five times, and I searched Google and StackOverflow pretty thoroughly. I'm seeing evidence that some people are getting past the initial connection to Sync API, so I'm fairly certain this API works.
Can someone help me understand what I'm missing? Could it just be that I need to wait a day or two for their systems to catch up? PayPal's Developer documentation is not very user-friendly, and their Developer Dashboard is extremely glitchy.
I had this same issue. Putting double quotes around the URL solved it for me. The other API endpoints worked (authentication, authorizations/xyz) because they didn't have any special URL characters in them. In the transaction search, the query string delimiters were being parsed by Bash.
Your curl lines above become:
curl -v -X GET "https://api.sandbox.paypal.com/v1/reporting/transactions?transaction_id=5TY05013RG002845M&fields=all&page_size=100&page=1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <my-access-token>"
Hope that helps someone.
It appears that this error may be caused by either cURL or the way I'm using it. On a hunch, I used Hurl.it to execute this sample request, and the request was successful (HTTP 200). I then tried another request where I searched for all transactions in a given date range, and that was also successful. I'm going to mark the question answered.
Is it possible to cancel a currently running build via REST API?
I've got an integration which fetches currently running builds, and I would like to terminate builds of a given type if they are failed. I know how to list the failing builds of a given type, how do I then pass the stop command?
Since TeamCity 8.1 it is possible to stop build using REST API:
curl -v -u user:password --request POST "http://localhost:7000/app/rest/buildQueue/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='true' />" --header "Content-Type: application/xml"
Maybe not with the REST API, but if you look here (towards the bottom in the Comments section) there's an 'undocumented' feature that lets you do it over HTTP.
Not exactly the REST call you were looking for, but you can simply do an HTTP POST to:
http://teamcity.my.org/viewLog.html?buildTypeId=bt278&buildId=1352480#
Where:
buildTypeId is your project's id
buildId is the build number to stop
Obviously, you can only do this while the build is running.