i'm trying to change the content of a page in xwiki with a put command .
in the rest API documentation of wiki:
HTTP Method: PUT
Accepted Media types:
application/xml (Page element)
text/plain (Only page content)
application/x-www-form-urlencoded (allowed field names: title, parent, content)
Media types:
application/xml (Page element)
Description: Create or updates a page.
Status codes:
201: If the page was created.
202: If the page was updated.
304: If the page was not modified.
401: If the user is not authorized.
i tried something like that :
$ curl -X PUT -text/plain -T"C:\Users\braimm\Desktop\text.txt" \
"http://localhost:8082/xwiki/rest/wikis/xwiki/spaces/Sandbox/pages/TestPage1/"
but it doesn't work, it seems that i have to specify the media types, does anyone try to do something like that, i want just to change the content of a page with a PUT command.
thanks
i did it with that:
$ curl -u user:password -X PUT -T "#content" -H "Content-Type: text/plain" \
localhost:8080/xwiki/rest/wikis/xwiki/spaces/Sandbox/pages/{PageName}
this one change the content of a page in wiki
Related
Need to update labels in merge request during gitlab ci. Tried different variants:
curl -X PUT https://gitlab.com/api/v4/projects/{project_id}/merge_requests/134?access_token={token}&labels=merged
Tried passing token as header and as data.
Tried passing "personal_token", "access_token", "token" and etc.
Getting {"message":"401 Unauthorized"} all the time.
I think that you should use private_token as it said on documentation:
curl https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>
or in the header, as you said:
curl --header "PRIVATE-TOKEN: xxx" "https://gitlab.com/api/v4/projects"
Have a look on the official page:
https://docs.gitlab.com/ee/api/README.html#personal-access-tokens
Example:
Getting information from merge request with iid 1(the actual labels are testlabel and testlabel3):
#curl -X GET https://gitlab.com/api/v4/projects/11209705/merge_requests/1?private_token={XXXXXX}
{"id":28761206,"iid":1,"project_id":1120970.......,"labels":["testlabel","testlabel3"],...}
Sending put with curl with "--data" and the parameter to update "labels" to "test":
# curl -X PUT https://gitlab.com/api/v4/projects/11209705/merge_requests/1?private_token={XXXXX} --data "labels=test"
Getting information from merge request with iid 1(the actual labels is "test"):
#curl -X GET https://gitlab.com/api/v4/projects/11209705/merge_requests/1?private_token={XXXXXX}
{"id":28761206,"iid":1,"project_id":1120970.......,"labels":["test"],...}
I want to use a GET URL to search and return a group of documents from MarkLogic API.
If I use a POST method I can set the Accpets:multipart/mixed header and return what I want. The environment I am using can only send GET URL.
How do I either add multipart/mixed to GET URL or how do I pass to MarkLogic API return documents.
The argument view=none returns an error
REST-UNSUPPORTEDPARAM: (err:FOER0000) Endpoint does not support query parameter: Can use the 'none' value for the 'view' parameter only with multipart/mixed accept
You indicate that you accept multipart/mixed by setting the Accept request header.
For example, with cURL:
curl --anyauth --user user:password -X GET -i \
-H "Accept: multipart/mixed; boundary=BOUNDARY" \
'http://localhost:8000/LATEST/search?view=none'
If you are trying to issue a GET search request from your browser with view=none, simply typing in the URL and hitting return may not work.
However, you can still make it work. For example, in FireFox you can:
Pop open the developer toolbar
Select the request
Under the "headers" tab, to the right of the status code, click the "edit and resend" button
In the Request Headers textarea, add "Accept: multipart/mixed; boundary=BOUNDARY"
Click the "Send" button
Select the newly issued request, click the "Response" tab to view your multipart response
So I got the data that is being sent to a specific server. Now I want to do the same using curl from my local machine to play around with specific repsonses from the server and learn more about curl as well.
Here is part of my data
POST /auth HTTP/1.1
platform: android
X-Auth-Token: <censored>
Content-Type: application/json; charset=utf-8
Host: api.blabla.com
Accept-Encoding: gzip
And the data that is being sent:
{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}
Now when I try cURL in my dos shell, I try
curl --insecure -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
The response I get from cURL is this:
{"code":401,"error":"blablaTokenRequired"}
Even though I specified the token. So there are two possible scenarios because the token is correct:
It has something to do with the SSL thing? (I use --insecure because I get an SSL error otherwise)
Something about my command is not correct but I can't figure out what.
Can someone kindly help me out? I am trying everything I can without success
I am not sure if I understand your application specific right, but probably one thing you need to take into account:
man curl says:
-d, --data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when
a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the
server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
-d, --data is the same as --data-ascii. --data-raw is almost the same but does not have a special interpreta‐
tion of the # character. To post data purely binary, you should instead use the --data-binary option. To URL-
encode the value of a form field you may use --data-urlencode.
As I can't see in your example the necessity of sending data as HTML form input, probably your application expects just a "raw" POST body and then you have to try this:
curl --insecure -X POST https://api.blabla.com/auth --data--binary '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
PS and for sure this is error is not about using --insecure which just asks curl to neglect ssl verification
you forgot the headers and enabling compressed encoding (gzip), however, i believe you can't force curl to only support gzip encoding using the curl command line alone, you will have to use libcurl, this will make the request say "Accept-Encoding: gzip,deflate" on most systems, using --compressed .. if that's not acceptable to you, rewrite it using libcurl (where you can force it to say only "gzip", if you wish, via CURLOPT_ENCODING )
curl -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}' --header 'platform: android' --header 'X-Auth-Token: <censored>' --header 'Content-Type: application/json; charset=utf-8' --header 'Host: api.blabla.com' --compressed
another gotcha: on some systems, there will be a default useragent header (like debian 6), while on some systems, curl comes without a default useragent (like debian 8).. you might want to use --user-agent '' too
I am using the Embeddable Reporting service for Bluemix. I want to dynamically change the SQL text in the SQLQuery of a report definition so that the report is generated from a referenced table. The report specification can be changed using the https://erservice-impl.ng.bluemix.net:443/ers/v1/definitions//specificationAPI. However, how do you change the SQL text?
Here are the steps that are involved:
Author a report in the your favorite authoring tool against a sample table.
Grab the report specification by clicking Tools > Copy Report to Clipboard.
Locate the SQL string in the report specificiation and change it to a token that you can easily search/replace. For example: Select * from %%DATATABLE%%
Save this template in a file or in a string variable within your app.
Search/replace the string %%DATATABLE%% with the table that you want.
Execute the report:
a. POST to /ers/v1/packages/(package-id)/reports with content-type application/xml and the specification as the body. The response will contain the location of the new report.
b. GET /ers/v1/reports/(report-id)/html to render the report in HTML.
Here is an example in curl:
Connect to the service with your cloudant/Mongo URL and Embeddable Reporting Service credentials. For example:
curl --insecure -i -X POST --cookie-jar newcookies.txt -H "Content-Type: application/json" -d '{"bundleUri":"https:/(repository-uri)/"}' https://(ers-userid):(ers-password)#erservice-impl.ng.bluemix.net/ers/v1/connection
Create a run instance from a specification against the packageId that contains your database.For example:
curl --insecure -i -X POST -b newcookies.txt -H "Content-Type: application/xml" -d '(report-spec-goes-here)' https://erservice-impl.ng.bluemix.net/ers/v1/packages/(package-id)/reports
Here is an example response:
{
...
"_links": {
"formats": [
{
"href": "/ers/v1/reports/JwVd3JkeR3SFUkLlOi1bWw/html",
"disposition": "paged",
"mimeType": "text/html"
},
... other formats ...
]
},
"_bundleID": "JwVd3JkeR3SFUkLlOi1bWw"
}
You can now run the response._links.formats.href
Run the instance in HTML. For example:
curl --insecure -i -X GET -b newcookies.txt https://erservice-impl.ng.bluemix.net:443/ers/v1/reports/JwVd3JkeR3SFUkLlOi1bWw/html
Get the HTML back.
I'm trying to add a user to a Github repository via their API, but I always get a 502 Bad Gateway error.
With curl I send a request like this (<...> replaced by a real owner, repo, etc.):
curl -i -H 'Authorization: token xxxxxxxxxx' -XPUT https://api.github.com/repos/<owner>/<repo>/collaborators/<username>
I also tried it with this url:
curl -i -H 'Authorization: token xxxxxxxxxx' -XPUT https://api.github.com/teams/<id>/members/<username>
As token I used a newly created Personal Access Tokens
But both times I get this back
HTTP/1.0 502 Bad Gateway
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>
A GET on each URL works fine but a DELETE doesn't work either. So maybe it has to do with curl.
Quoting the reply from GitHub's support with changes in italic:
You're just getting trolled by HTTP and curl.
When you make a PUT request with no body, curl doesn't explicitly set a Content-Length header for that request. However, PUT requests with no Content-Length confuse servers and they respond in weird ways.
Can you please try explicitly setting the Content-Lenght header to 0, or supplying an empty body when making that request (so that curl can set the header for you)? You can accomplish that adding -d "" in your command.