How to update a page in confluence using its REST API - confluence

I added an attachment successfully to the confluence page but i am unable to update that page. I do have admin permissions to create a page and edit it. I do not know why its not working. Below is the command that i have used to update a page in confluence.
curl -u username:password -X PUT -H 'Content-Type: application/json' -d'{"id":"pageid","type":"page","title":"LOAD-UI REPORTS","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is the updated text for the loadui reports page</p>","representation":"storage"}},"version":{"number":2}}' https://jira.hilton.com/confluence/rest/api/content/pageid | python -mjson.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
397 177 0 177 0 220 359 446 --:--:-- --:--:-- --:--:-- 0
{
"data": {
"authorized": false,
"errors": [],
"valid": true
},
"message": "Could not update Content of type : class com.atlassian.confluence.pages.Page with id 38012230",
"statusCode": 400
}
Please let me know what i am doing wrong here.

Related

Why using Google Cloud Drive Rest API file.list can not get all the files?

I am using the following CURL command to retrieve all my google drive files, however, it only list a very limited part of the whole bunch of files. Why?
curl -H "Authorization: Bearer ya29.hereshouldbethemaskedaccesstokenvalue" https://www.googleapis.com/drive/v3/files
result
{
"kind": "drive#fileList",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
id": "2fileidxxxxxxxx",
"name": "testnum",
"mimeType": "application/vnd.google-apps.folder"
},
{
"kind": "drive#file",
"id": "1fileidxxxxxxx",
"name": "test2.txt",
...
}
token scope includes
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.appdata
Using the Android SDK also facing the same issue.
Any help would be appreciated.
Results from files.list are paginated -- your response should include a "nextPageToken" field, and you'll have to make another call for the next page of results. See documentation here about the files list call. You may want to use one of the client libraries to make this call (see the examples at the bottom of the page)
I have the same problem when try to get list of files in Google Drive folder. This folder has more than 5000 files, but API return only two of them. The problem is -- when files in folder shared with anyone with a link, in fact it isn't shared with you until you open it. Owner of this folder must specify you as viewer.

how to do a put for camel-example-swagger-cdi?

I can do get on camel-example-swagger-cdi. But how do I do a put ?
I tried the following on browser, it didn't work at all.
http://localhost:8080/user/{'id':'222','name':'Richard'}.
And I tried the following curl command, it didn't work either
curl -X PUT -d id=222 -d name="Richard" localhost:8080/user
Please advise how I can issue a post
public class UserRouteBuilder extends RouteBuilder {
#Override
public void configure() throws Exception {
// configure we want to use servlet as the component for the rest DSL
// and we enable json binding mode
restConfiguration().component("netty4-http").bindingMode(RestBindingMode.json)
// and output using pretty print
.dataFormatProperty("prettyPrint", "true")
// setup context path and port number that netty will use
.contextPath("/").port(8080)
// add swagger api-doc out of the box
.apiContextPath("/api-doc")
.apiProperty("api.title", "User API").apiProperty("api.version", "1.2.3")
// and enable CORS
.apiProperty("cors", "true");
// this user REST service is json only
rest("/user").description("User rest service")
.consumes("application/json").produces("application/json")
.get("/{id}").description("Find user by id").outType(User.class)
.param().name("id").type(path).description("The id of the user to get").dataType("int").endParam()
.to("bean:userService?method=getUser(${header.id})")
.put().description("Updates or create a user").type(User.class)
.param().name("body").type(body).description("The user to update or create").endParam()
.to("bean:userService?method=updateUser")
.get("/findAll").description("Find all users").outTypeList(User.class)
.to("bean:userService?method=listUsers");
}
}
I used Postman to do a put:
localhost:8080/user?body={'id':'222' , 'name':'Richard' }
Got
Used Postman to do a put. Got
java.net.URISyntaxException: Illegal character in query at index 11: /user?body=
{%27id%27:%272222%27%20,%20%27name%27:%27Richard%27%20}
I got the following exception when I run curl to put.
$ curl -X PUT -d "body={'id':'222','name':'Richard'}" http://localhost:8080/user
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3142 100 3108 100 34 33419 365 --:--:-- --:--:-- --:--:-- 50129com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'body': was expecting ('true', 'false' or 'null')
at [Source: java.io.ByteArrayInputStream#17b2613c; line: 1, column: 6]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1581)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:533)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3451)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2610)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:841)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:737)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3776)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3721)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2796)
at org.apache.camel.component.jackson.JacksonDataFormat.unmarshal(JacksonDataFormat.java:173)
at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69)
at org.apache.camel.processor.binding.RestBindingProcessor.process(RestBindingProcessor.java:168)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.component.netty4.handlers.ServerChannelHandler.processAsynchronously(ServerChannelHandler.java:134)
at org.apache.camel.component.netty4.handlers.ServerChannelHandler.channelRead0(ServerChannelHandler.java:105)
at org.apache.camel.component.netty4.http.handlers.HttpServerChannelHandler.channelRead0(HttpServerChannelHandler.java:211)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at org.apache.camel.component.netty4.http.handlers.HttpServerMultiplexChannelHandler.channelRead0(HttpServerMultiplexChannelHandler.java:113)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:42)
at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:309)
at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:36)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:724)
If you can use GUI tools you should take a look at Postman, otherwise you can run:
curl -X PUT -d "{'id':'222','name':'Richard'}" http://localhost:8080/user
I would also recommend you to take a look at PUT vs POST in REST, and Swagger's Parameter Object docs.
I figured it out. And it is working now. curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{ \"id\": 222,\"name\": \"Richard\"}" http://localhost:8080/user

Run a MapReduce job via rest api

I use hadoop2.7.1's rest apis to run a mapreduce job outside the cluster. This example "http://hadoop-forum.org/forum/general-hadoop-discussion/miscellaneous/2136-how-can-i-run-mapreduce-job-by-rest-api" really helped me. But when I submit a post response, some strange things happen:
I look at "http://master:8088/cluster/apps" and a post response produce two jobs as following picture:
strange things: a response produces two jobs
After wait a long time, the job which I defined in the http response body fail because of FileAlreadyExistsException. The reason is another job creates the output directory, so Output directory hdfs://master:9000/output/output16 already exists.
This is my response body:
{
"application-id": "application_1445825741228_0011",
"application-name": "wordcount-demo",
"am-container-spec": {
"commands": {
"command": "{{HADOOP_HOME}}/bin/hadoop jar /home/hadoop/hadoop-2.7.1/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar wordcount /data/ /output/output16"
},
"environment": {
"entry": [{
"key": "CLASSPATH",
"value": "{{CLASSPATH}}<CPS>./*<CPS>{{HADOOP_CONF_DIR}}<CPS>{{HADOOP_COMMON_HOME}}/share/hadoop/common/*<CPS>{{HADOOP_COMMON_HOME}}/share/hadoop/common/lib/*<CPS>{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/*<CPS>{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/lib/*<CPS>{{HADOOP_YARN_HOME}}/share/hadoop/yarn/*<CPS>{{HADOOP_YARN_HOME}}/share/hadoop/yarn/lib/*<CPS>./log4j.properties"
}]
}
},
"unmanaged-AM": false,
"max-app-attempts": 2,
"resource": {
"memory": 1024,
"vCores": 1
},
"application-type": "MAPREDUCE",
"keep-containers-across-application-attempts": false
}
and this is my command:
curl -i -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' http://master:8088/ws/v1/cluster/apps?user.name=hadoop -d #post-json.txt
Can anybody help me? Thanks a lot.
When you run the map reduce, see that you do not have output folder as the job will not run if it is present. You can write program so that you can delete the folder is it exists, or manually delete it before calling the rest api. This is just to prevent the data loss and avoid overwriting the output of other job.

CloudSQL - Export data - Using google-api-services-sqladmin - v1beta4

I'm new to cloudSQL, trying to build a small console application to test the functionalities of CLoudSQL API. (google-api-services-sqladmin - v1beta4)
Can somebody help me to get start with some sample code?
For example, i want to export data from cloudSQL to GCS using - select query?
Here's a sample HTTP request that will export the table mysql.user to a CSV file in Cloud Storage:
POST https://www.googleapis.com/sql/v1beta4/projects/<project>/instances/<instance>/export
content-type: application/json
content-length: <length-of-request-body>
Authorization: Bearer <access-token>
{
"exportContext": {
"csvExportOptions": {
"selectQuery": "SELECT * FROM mysql.user"
},
"uri": "gs://<bucket>/users.csv",
"fileType": "CSV"
}
}
Note that you need to set the values for <project>, <instance>, <access-token>, and <bucket>.
Once you have those parameters, you can easily try this either using the API Explorer, at the bottom where it says "try it".
Or simply by using curl:
CURL command:
$ curl -X POST \
https://www.googleapis.com/sql/v1beta4/projects/<project>/instances/<instance>/export \
-H'content-length: <length-of-request-body>'
-H'content-type: application/json'
-H'Authorization: Bearer <access-token>'
-d'{"exportContext": {"csvExportOptions": {"selectQery": "SELECT * FROM mysql.user"}, "fileType": "CSV", "uri": "gs://<bucket>/users.csv"}}'

Track number of download of a release (binaries) on Github

So now you can manage and publish your binaries directly on Github, the feature is back from early this month (source).
I've been looking around Github interface and I haven't seen a download tracker. This is a feature Google Code offer and I was wondering if Github has the same.
Please note, I am not interested to know the number of download of a repo, this is a different topic.
Based on Petros answer, I used the two following curl command:
To get the list of all releases including their id and number of
download:
curl -i https://api.github.com/repos/:owner/:repo/releases -H "Accept: application/vnd.github.manifold-preview+json"
For example to list all the release for the OpenRefine project:
curl -i https://api.github.com/repos/openrefine/openrefine/releases -H "Accept: application/vnd.github.manifold-preview+json"
Then to get details on each release (you will need to run the first query to get the release id)
curl -i https://api.github.com/repos/:owner/:repo/releases/assets/:release_id -H "Accept: application/vnd.github.manifold-preview+json"
With the same example to list the details including download number for google-refine-2.5-r2407.zip
curl -i https://api.github.com/repos/openrefine/openrefine/releases/assets/6513 -H "Accept: application/vnd.github.manifold-preview+json"
You can use the GitHub API to get the download_count among other things for a single release asset:
http://developer.github.com/v3/repos/releases/#get-a-single-release-asset
This is how it looks currently, but please check the link above just in case anything changed since this answer was written.
GET /repos/:owner/:repo/releases/assets/:id
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1",
"id": 1,
"name": "example.zip",
"label": "short description",
"state": "uploaded",
"content_type": "application/zip",
"size": 1024,
"download_count": 42,
"created_at": "2013-02-27T19:35:32Z",
"updated_at": "2013-02-27T19:35:32Z"
}
You can add a badge to your github repo. See this answer for more details.
Also, there is a nifty project that shows all of this data in a nice website which is over here: https://www.somsubhra.com/github-release-stats/