This is what I've currently got and it creates a new Confluence page. It doesn't update it. Also it posts it in the root space, TST, but I want it to be in TST/space1/subsection2/updateThisPage.
curl -v -u admin:admin -X POST -H Content-Type: application/json -d "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
This is the error message I get
{"statusCode":400,"message":"A page with this title already exists: A page already exists with the title new page in the space with key TST"}
Would it be a permissions error? I know I do not have access to delete.
Use request /rest/api/content/{id}.
This worked for me.
curl -u admin:admin -X PUT -H "Content-Type: application/json" -d "{\"id\":\"26738701\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"RO\"},\"body\":{\"storage\":{\"value\":\"<p>UPDATE This is a new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":2}}" http://localost:10080/rest/api/content/26738701
JSON Payload:
{
"id":"26738701",
"type":"page",
"title":"new page",
"space":{
"key":"RO"
},
"body":{
"storage":{
"value":"<p>UPDATE This is a new page</p>",
"representation":"storage"
}
},
"version":{
"number":2
}
}
Don't forget to use:
content ID in data part
version number in data part
PUT request
content ID in request
Try to use PUT instead of POST.
curl -v -u admin:admin -X PUT -H Content-Type: application/json -d "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
If anyone is looking for javascript solution, here is my answer to another question like that
Unexpected grunt-http error when posting to Atlassian Confluence api
And here you can find working code i've developed on confluence hackathon
https://github.com/devex-web-frontend/dxWebPlugins/blob/master/src/confluence/helpers/buffer.js
Related
This curl is working fine and returns the token as expected:
curl -X POST -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "username": "pere.peris#gmail.com","password": "password" }' "http://75.90.255.68:1133/canPeris/auth"
But when I do the same call using Postman app I get a 401 Unauthorized as a return value
You should add the missing JSON inside the Body . click Raw combo box and add
{ "username": "pere.peris#gmail.com","password": "password" }
You can use the function in Postman to generate curl:
https://www.getpostman.com/docs/v6/postman/sending_api_requests/generate_code_snippets
On the right side under "Send" and "Save" just hit the Code Button/Link. Then select in the next window in the drop down cURL. So you see what cURL would be generated and compare it with the command line.
The -d option is described here: https://curl.haxx.se/docs/manpage.html#-d
I currently trying to get the issues from JIRA via REST API via this:
curl -D- -u USERNAME -X GET -H "Content-Type: application/json" \
https://issues.apache.org/jira/rest/api/2/search? jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0 \
-o release.json
But unfortunately i don't get all issues. Only 50 instead of 59. I already checked if all the issues have the correct fixVersion set to 3.4.0.
But via browser:
https://issues.apache.org/jira/issues/?jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0
I got all the issues.
Do i oversight something ? Some idea hint ?
50 is a default value for "maxResults" parameter. Here's API documentation https://docs.atlassian.com/jira/REST/latest/#api/2/search-search
I am testing my ZF2 Rest Module that is running on localhost, by sending curl POST requests from the same box.
curl -i -X POST -H "Content-Type: Application/json" -d '{username":"xyz","password":"xyz"}' http://localhost/api/login
In the corresponding controller and action, I have tried returning the POST parameters, but an empty array is returned always
var_dump($this->getRequest()); // returns: array(0){}
var_dump($_POST); // returns: array(0){}
If I switch from POST to GET with
curl -i -G -H "Content-Type: Application/json" -d '{username":"xyz","password":"xyz"}' http://localhost/api/login
it actually seems to work
var_dump($_GET); // returns: array(1) {["{"username":"xyz","password":"xyz"}"]=>string(0) ""}
Why is the POST request failing to pass/extract the parameters?
PHP only populates $_POST for form urlencoded POST data. You've explicitly set the content type to JSON, so the PHP way to access this would be:
file_get_contents("php://input");
In ZF2, I believe you want:
$this->getRequest()->getContent();
and in practice, you'll probably want to run this through json_decode().
I am using cURL command line utility to send HTTP POST to a web service. I want to include a file's contents as the body entity of the POST. I have tried using -d </path/to/filename> as well as other variants with type info like --data </path/to/filename> --data-urlencode </path/to/filename> etc... the file is always attached. I need it as the body entity.
I believe you're looking for the #filename syntax, e.g.:
strip new lines
curl --data "#/path/to/filename" http://...
keep new lines
curl --data-binary "#/path/to/filename" http://...
curl will strip all newlines from the file. If you want to send the file with newlines intact, use --data-binary in place of --data
I know the question has been answered, but in my case I was trying to send the content of a text file to the Slack Webhook api and for some reason the above answer did not work. Anywho, this is what finally did the trick for me:
curl -X POST -H --silent --data-urlencode "payload={\"text\": \"$(cat file.txt | sed "s/\"/'/g")\"}" https://hooks.slack.com/services/XXX
In my case, # caused some sort of encoding problem, I still prefer my old way:
curl -d "$(cat /path/to/file)" https://example.com
curl https://upload.box.com/api/2.0/files/3300/content -H "Authorization: Bearer $access_token" -F file=#"C:\Crystal Reports\Crystal Reports\mysales.pdf"
I'm attempting to gather XML data automatically using curl, and my command so far is
curl -E keyStore.pem -d 'uid=myusername&password=mypassword&active=y&type=F' 'https://www.aidaptest.naimes.faa.gov/aidap/XmlNotamServlet HTTP/1.1/' -k
but it keeps on giving me a "Your browser sent a query this server could not understand." error.
I'm pretty sure that it's connecting since it's not rejecting me, but I don't know how to properly format the POST. Here's some documentation they gave me for the format of the POST request.
POST <URL>/aidap/XmlNotamServlet HTTP/1.1
Content-type: application/x-www-form-urlencoded
Content-length: <input_parameter’s length>
<a blank line>
<input_parameter>`
input_parameter is uid, password, and location_id bit and is correct
Am I doing this correctly from what you can see?
Something like this should do it.
curl -E keyStore.pem -v -X POST -i --header Content-Type:application/x-www-form-urlencoded
-d 'uid=myusername&password=mypassword&active=y&type=F' 'https://www.aidaptest.naimes.faa.gov/aidap/XmlNotamServlet'
I don't think you need HTTP/1.1 at the end of the URL in the command line. And even if you needed it, you certainly don't need the final / character before the closing single quote.