curl get is omitting json that is shown in the browser - json

I'm working with the confluence API and testing some endpoints in the browser to make sure it returns the right information and then fetching with curl.
When I go to the following url:
http://localhost:8090/rest/api/content/search?cql=label+%3D+%22program-status-rollup-employee%22&expand=space
I get the following JSON:
{
"results": [
{
"id": "2064397",
"type": "page",
"status": "current",
"title": "TL Employee Reports",
"space": {
"id": 98306,
"key": "COM",
"name": "Compass",
"type": "global",
"_expandable": {
"metadata": "",
"icon": "",
"description": "",
"homepage": "/rest/api/content/65584"
},
"_links": {
"self": "http://localhost:8090/rest/api/space/COM",
"webui": "/display/COM"
}
},
"extensions": {
"position": "none"
},
"_expandable": {
"container": "/rest/api/space/COM",
"metadata": "",
"operations": "",
"children": "/rest/api/content/2064397/child",
"restrictions": "/rest/api/content/2064397/restriction/byOperation",
"history": "/rest/api/content/2064397/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/2064397/descendant"
},
"_links": {
"self": "http://localhost:8090/rest/api/content/2064397",
"webui": "/display/COM/TL+Employee+Reports",
"edit": "/pages/resumedraft.action?draftId=2064397&draftShareId=0906da34-3930-4c15-8339-d85c309f6cc0",
"tinyui": "/x/DYAf"
}
},
{
"id": "2064402",
"type": "page",
"status": "current",
"title": "Employee Reports",
"space": {
"id": 2162689,
"key": "NC",
"name": "New Compass",
"type": "global",
"_expandable": {
"metadata": "",
"icon": "",
"description": "",
"homepage": "/rest/api/content/2064389"
},
"_links": {
"self": "http://localhost:8090/rest/api/space/NC",
"webui": "/display/NC"
}
},
"extensions": {
"position": "none"
},
"_expandable": {
"container": "/rest/api/space/NC",
"metadata": "",
"operations": "",
"children": "/rest/api/content/2064402/child",
"restrictions": "/rest/api/content/2064402/restriction/byOperation",
"history": "/rest/api/content/2064402/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/2064402/descendant"
},
"_links": {
"self": "http://localhost:8090/rest/api/content/2064402",
"webui": "/display/NC/Employee+Reports",
"edit": "/pages/resumedraft.action?draftId=2064402&draftShareId=8fb3e862-e52f-498d-83d5-6b6046682070",
"tinyui": "/x/EoAf"
}
},
{
"id": "819224",
"type": "page",
"status": "current",
"title": "Employee Reports",
"space": {
"id": 98306,
"key": "COM",
"name": "Compass",
"type": "global",
"_expandable": {
"metadata": "",
"icon": "",
"description": "",
"homepage": "/rest/api/content/65584"
},
"_links": {
"self": "http://localhost:8090/rest/api/space/COM",
"webui": "/display/COM"
}
},
"extensions": {
"position": "none"
},
"_expandable": {
"container": "/rest/api/space/COM",
"metadata": "",
"operations": "",
"children": "/rest/api/content/819224/child",
"restrictions": "/rest/api/content/819224/restriction/byOperation",
"history": "/rest/api/content/819224/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/819224/descendant"
},
"_links": {
"self": "http://localhost:8090/rest/api/content/819224",
"webui": "/display/COM/Employee+Reports",
"edit": "/pages/resumedraft.action?draftId=819224&draftShareId=0df4eb62-9bb6-4532-a445-4002695dcb90",
"tinyui": "/x/GIAM"
}
}
],
"start": 0,
"limit": 25,
"size": 3,
"_links": {
"base": "http://localhost:8090",
"context": "",
"self": "http://localhost:8090/rest/api/content/search?expand=space&cql=label+%3D+%22program-status-rollup-employee%22"
}
}
But when I get the same endpoint via curl:
curl -u $user:$password http://localhost:8090/rest/api/content/search?cql=label+%3D+%22program-status-rollup-employee%22&expand=space
I don't get all of the information:
{
"results":[
{
"id":"2064397",
"type":"page",
"status":"current",
"title":"TL Employee Reports",
"restrictions":{
},
"_expandable":{
"container":"",
"metadata":"",
"extensions":"",
"operations":"",
"children":"",
"history":"/rest/api/content/2064397/history",
"ancestors":"",
"body":"",
"version":"",
"descendants":"",
"space":"/rest/api/space/COM"
},
"_links":{
"self":"http://localhost:8090/rest/api/content/2064397",
"webui":"/display/COM/TL+Employee+Reports",
"tinyui":"/x/DYAf"
}
},
{
"id":"2064402",
"type":"page",
"status":"current",
"title":"Employee Reports",
"restrictions":{
},
"_expandable":{
"container":"",
"metadata":"",
"extensions":"",
"operations":"",
"children":"",
"history":"/rest/api/content/2064402/history",
"ancestors":"",
"body":"",
"version":"",
"descendants":"",
"space":"/rest/api/space/NC"
},
"_links":{
"self":"http://localhost:8090/rest/api/content/2064402",
"webui":"/display/NC/Employee+Reports",
"tinyui":"/x/EoAf"
}
},
{
"id":"819224",
"type":"page",
"status":"current",
"title":"Employee Reports",
"restrictions":{
},
"_expandable":{
"container":"",
"metadata":"",
"extensions":"",
"operations":"",
"children":"",
"history":"/rest/api/content/819224/history",
"ancestors":"",
"body":"",
"version":"",
"descendants":"",
"space":"/rest/api/space/COM"
},
"_links":{
"self":"http://localhost:8090/rest/api/content/819224",
"webui":"/display/COM/Employee+Reports",
"tinyui":"/x/GIAM"
}
}
],
"start":0,
"limit":25,
"size":3,
"_links":{
"base":"http://localhost:8090",
"context":"",
"self":"http://localhost:8090/rest/api/content/search?cql=label+%3D+%22program-status-rollup-employee%22"
}
}
Specifically it omits the space object, which I need. Any thoughts?

I needed to escape the ampersand with single quotes. Once I did that, it returned the json that I saw in the browser
http://localhost:8090/rest/api/content/search?cql=label+%3D+%22program-status-rollup-employee%22'&'expand=space

Related

how do i retrieve specific value from json with jq [duplicate]

This question already has answers here:
Passing bash variable to jq
(10 answers)
Closed 12 months ago.
i have a json file containing data about Jenkins stages.
assuming i have the stage name stored in a variable how do i retrieve the "durationMillis" value from that stage
STAGE1="CLEANUP WORKSTATION"
so far i was able to dissect the last job (json containing 3 last Jenkins jobs)
cat file.json | jq '.[] | select(.id=='\"$BUILD_NUMBER\"')'
outcome should present "157"
[
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/wfapi/describe"
}
},
"id": "72",
"name": "#72",
"status": "SUCCESS",
"startTimeMillis": 1646952992850,
"endTimeMillis": 1646953018448,
"durationMillis": 25598,
"queueDurationMillis": 24,
"pauseDurationMillis": 0,
"stages": [
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/8/wfapi/describe"
}
},
"id": "8",
"name": "CLEANUP WORKSTATION",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953001559,
"durationMillis": 157,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/12/wfapi/describe"
}
},
"id": "12",
"name": "GIT CLONE",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953001716,
"durationMillis": 302,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/25/wfapi/describe"
}
},
"id": "25",
"name": "ALL STAGES",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953002199,
"durationMillis": 893,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/33/wfapi/describe"
}
},
"id": "33",
"name": "STAGE1",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953003092,
"durationMillis": 3760,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/35/wfapi/describe"
}
},
"id": "35",
"name": "STAGE2",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953003196,
"durationMillis": 7348,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/37/wfapi/describe"
}
},
"id": "37",
"name": "STAGE3",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953003241,
"durationMillis": 5522,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/72/execution/node/90/wfapi/describe"
}
},
"id": "90",
"name": "Declarative: Post Actions",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646953010757,
"durationMillis": 7430,
"pauseDurationMillis": 0
}
]
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/wfapi/describe"
}
},
"id": "71",
"name": "#71",
"status": "SUCCESS",
"startTimeMillis": 1646952745744,
"endTimeMillis": 1646952770031,
"durationMillis": 24287,
"queueDurationMillis": 19,
"pauseDurationMillis": 0,
"stages": [
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/8/wfapi/describe"
}
},
"id": "8",
"name": "CLEANUP WORKSTATION",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952754330,
"durationMillis": 203,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/12/wfapi/describe"
}
},
"id": "12",
"name": "GIT CLONE",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952754533,
"durationMillis": 457,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/25/wfapi/describe"
}
},
"id": "25",
"name": "ALL STAGES",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952756222,
"durationMillis": 536,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/33/wfapi/describe"
}
},
"id": "33",
"name": "STAGE1",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952756758,
"durationMillis": 4344,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/35/wfapi/describe"
}
},
"id": "35",
"name": "STAGE2",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952756811,
"durationMillis": 6175,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/37/wfapi/describe"
}
},
"id": "37",
"name": "STAGE3",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952756842,
"durationMillis": 4167,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/71/execution/node/90/wfapi/describe"
}
},
"id": "90",
"name": "Declarative: Post Actions",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952763230,
"durationMillis": 6588,
"pauseDurationMillis": 0
}
]
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/wfapi/describe"
}
},
"id": "70",
"name": "#70",
"status": "FAILED",
"startTimeMillis": 1646952648485,
"endTimeMillis": 1646952669992,
"durationMillis": 21507,
"queueDurationMillis": 16,
"pauseDurationMillis": 0,
"stages": [
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/8/wfapi/describe"
}
},
"id": "8",
"name": "CLEANUP WORKSTATION",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952657661,
"durationMillis": 177,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/12/wfapi/describe"
}
},
"id": "12",
"name": "GIT CLONE",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952657838,
"durationMillis": 349,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/25/wfapi/describe"
}
},
"id": "25",
"name": "ALL STAGES",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952658407,
"durationMillis": 198,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/33/wfapi/describe"
}
},
"id": "33",
"name": "STAGE1",
"execNode": "",
"status": "FAILED",
"error": {
"message": "script returned exit code 2",
"type": "hudson.AbortException"
},
"startTimeMillis": 1646952658605,
"durationMillis": 3434,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/35/wfapi/describe"
}
},
"id": "35",
"name": "STAGE2",
"execNode": "",
"status": "FAILED",
"error": {
"message": "script returned exit code 2",
"type": "hudson.AbortException"
},
"startTimeMillis": 1646952658638,
"durationMillis": 5948,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/37/wfapi/describe"
}
},
"id": "37",
"name": "STAGE3",
"execNode": "",
"status": "FAILED",
"error": {
"message": "script returned exit code 2",
"type": "hudson.AbortException"
},
"startTimeMillis": 1646952658669,
"durationMillis": 3969,
"pauseDurationMillis": 0
},
{
"_links": {
"self": {
"href": "/jenkins/cag-sw-jenkins/job/test/job/test-hagay-elk-kv/70/execution/node/90/wfapi/describe"
}
},
"id": "90",
"name": "Declarative: Post Actions",
"execNode": "",
"status": "SUCCESS",
"startTimeMillis": 1646952664887,
"durationMillis": 4873,
"pauseDurationMillis": 0
}
]
}
]
i worked it a bit and was able to extract what i needed
export BUILD_NUMBER='72'
export STAGE1="CLEANUP WORKSTATION"
cat file.json | jq '.[] | select(.id==env.BUILD_NUMBER) | .stages | .[] | select(.name | contains(env.STAGE1)) | .durationMillis'

Kubernetes + jq - retrieving containers list per pod yields cartesian product

Im trying to use jq on kubernetes json output, to create new json object containing list of objects - container and image per pod, however im getting cartesian product.
my input data (truncated from sensitive info):
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"creationTimestamp": "2021-06-30T12:45:40Z",
"name": "pod-1",
"namespace": "default",
"resourceVersion": "757679286",
"selfLink": "/api/v1/namespaces/default/pods/pod-1"
},
"spec": {
"containers": [
{
"image": "image-1",
"imagePullPolicy": "Always",
"name": "container-1",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"readOnly": true
}
]
},
{
"image": "image-2",
"imagePullPolicy": "Always",
"name": "container-2",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"readOnly": true
}
]
}
],
"dnsPolicy": "ClusterFirst",
"enableServiceLinks": true,
"priority": 0,
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 30,
"tolerations": [
{
"effect": "NoExecute",
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"tolerationSeconds": 300
},
{
"effect": "NoExecute",
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"tolerationSeconds": 300
}
],
"volumes": [
{
"name": "default-token-b954f",
"secret": {
"defaultMode": 420,
"secretName": "default-token-b954f"
}
}
]
},
"status": {
"conditions": [
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"message": "containers with unready status: [container-1 container-2]",
"reason": "ContainersNotReady",
"status": "False",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"message": "containers with unready status: [container-1 container-2]",
"reason": "ContainersNotReady",
"status": "False",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"status": "True",
"type": "PodScheduled"
}
],
"containerStatuses": [
{
"image": "image-1",
"imageID": "",
"lastState": {},
"name": "container-1",
"ready": false,
"restartCount": 0,
"started": false,
"state": {
"waiting": {
"message": "Back-off pulling image \"image-1\"",
"reason": "ImagePullBackOff"
}
}
},
{
"image": "image-2",
"imageID": "",
"lastState": {},
"name": "container-2",
"ready": false,
"restartCount": 0,
"started": false,
"state": {
"waiting": {
"message": "Back-off pulling image \"image-2\"",
"reason": "ImagePullBackOff"
}
}
}
],
"qosClass": "BestEffort",
"startTime": "2021-06-30T12:45:40Z"
}
}
],
"kind": "List",
"metadata": {
"resourceVersion": "",
"selfLink": ""
}
}
my command:
jq '.items[] | { "name": .metadata.name, "containers": [{ "name": .spec.containers[].name, "image": .spec.containers[].image }]} '
desired output:
{
"name": "pod_1",
"containers": [
{
"name": "container_1",
"image": "image_1"
},
{
"name": "container_2",
"image": "image_2"
}
]
}
output I get:
{
"name": "pod-1",
"containers": [
{
"name": "container-1",
"image": "image-1"
},
{
"name": "container-1",
"image": "image-2"
},
{
"name": "container-2",
"image": "image-1"
},
{
"name": "container-2",
"image": "image-2"
}
]
}
Could anyone explain what am I doing wrong?
Best Regards, Piotr.
The problem is "name": .spec.containers[].name and "image": .spec.containers[].image:
Both expressions generate a sequence of each value for name and image which will than be combined.
Simplified example of why you get a Cartesian product:
jq -c -n '{name: ("A", "B"), value: ("C", "D")}'
outputs:
{"name":"A","value":"C"}
{"name":"A","value":"D"}
{"name":"B","value":"C"}
{"name":"B","value":"D"}
You get the desired output using this jq filter on your input:
jq '
.items[]
| {
"name": .metadata.name,
"containers": .spec.containers
| map({name, image})
}'
output:
{
"name": "pod-1",
"containers": [
{
"name": "container-1",
"image": "image-1"
},
{
"name": "container-2",
"image": "image-2"
}
]
}

JSON path extractor

I have the following JSON response and I wanted to build the JSON expression to extract the "connectionId" based on given "systemId" and "connectionConfig"."type" value. For example, extract "connectionId" for "systemId"= 'DHB_K8S_HADOOP_SYS' and "connectionConfig"."type"='S3'
{
"browse": [
{
"name": "DHB_K8S_HDFS_Conn1",
"type": "connection",
"connectionId": "DHB_K8S_HDFS_Conn1",
"systemId": "DHB_K8S_HADOOP_SYS",
"uri": "hdfs:///",
"connectionConfig": {
"type": "HDFS",
"description": "",
"connection": "",
"protocol": "",
"authentication": {
"type": "",
"user": "vora"
},
"systemId": "DHB_K8S_HADOOP_SYS",
"zoneId": "DHB_Zone"
},
"children": [
{}
]
},
{
"name": "DHB_K8S_HDFS_S3_Conn1",
"type": "connection",
"connectionId": "DHB_K8S_HDFS_S3_Conn1",
"systemId": "DHB_K8S_HADOOP_SYS",
"uri": "s3a:/",
"connectionConfig": {
"type": "S3",
"description": "",
"connection": "",
"protocol": "",
"authentication": {},
"systemId": "DHB_K8S_HADOOP_SYS",
"zoneId": "DHB_Zone"
},
"children": [
{}
]
},
{
"name": "DHB_K8S_VORA_S3",
"type": "connection",
"connectionId": "DHB_K8S_VORA_S3",
"systemId": "DHB_K8S_VORA_SYS",
"uri": "s3a:/",
"connectionConfig": {
"type": "S3",
"description": "",
"connection": "",
"protocol": "",
"authentication": {},
"systemId": "DHB_K8S_VORA_SYS",
"zoneId": "DHB_Zone"
},
"children": [
{}
]
}
]
}
Any help is appreciated

Reading hierarchy of a JSON using value

I want to get the hierarchy of a JSON using a value. For example: In below JSON for value "Medical record number" , the desired information is "resource->identifier->type->coding->display" . IS their any inbuilt function to do so.
The one way to look for opening and ending braces to locate nodes. Any other efficient way ?
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "Patient/996-756-495-101",
"resource": {
"resourceType": "Patient",
"id": "996-756-495-101",
"identifier": [
{
"type": {
"coding": [
{
"system": "http://hl7.org/fhir/v2/0203",
"code": "MR",
"display": "Medical record number"
}
]
},
"system": "https://www.lumc.nl",
"value": "996-756-495-101"
}
],
"name": [
{
"use": "usual",
"family": [
"Levin_4"
],
"given": [
"Henry_4"
]
}
],
"gender": "male",
"birthDate": "1932-09-24",
"maritalStatus": {
"coding": [
{}
]
},
"managingOrganization": {
"reference": "Organization/12"
}
},
"request": {
"method": "POST",
"url": "Patient",
"ifNoneExist": "identifier=https://www.lumc.nl|996-756-495-101"
}
},
{
"fullUrl": "FamilyMemberHistory/d42ebf70-5c89-11db-b0de-0800200c9a66",
"resource": {
"resourceType": "FamilyMemberHistory",
"id": "d42ebf70-5c89-11db-b0de-0800200c9a66",
"patient": {
"reference": "Patient/996-756-495-101"
},
"status": "Partial",
"relationship": {
"coding": [
{
"system": "http://hl7.org/fhir/ValueSet/v3-FamilyMember",
"code": "FTH",
"display": "Father"
}
],
"text": "Father"
},
"gender": "male",
"bornDate": "1912",
"deceasedBoolean": true
},
"request": {
"method": "POST",
"url": "FamilyMemberHistory"
}
},
{
"fullUrl": "FamilyMemberHistory/a13c6160-5c8b-11db-b0de-0800200c9a66",
"resource": {
"resourceType": "FamilyMemberHistory",
"id": "a13c6160-5c8b-11db-b0de-0800200c9a66",
"patient": {
"reference": "Patient/996-756-495-101"
},
"status": "Partial",
"relationship": {
"coding": [
{
"system": "http://hl7.org/fhir/ValueSet/v3-FamilyMember",
"code": "MTH",
"display": "Mother"
}
],
"text": "Mother"
},
"gender": "female",
"bornDate": "1912",
"deceasedBoolean": false
},
"request": {
"method": "POST",
"url": "FamilyMemberHistory"
}
}
]
}

How to get all versions of Confluence page via REST API

I would like to retrieve all versions of a page in Confluence. There is a call in the REST API that claims to return the history, but I have little luck with it.
/rest/api/content/{id}/history
When I call this I get a response along these lines:
{"latest": true,
"createdBy": {
"type": "known",
"profilePicture": {
"path": "/confluence/s/en_GB/.../profilepics/Avatar-14.png",
"width": 48,
"height": 48,
"isDefault": false
},
"username": "first.last#abc123.com",
"displayName": "First Last",
"userKey": "userKey"
}, "createdDate": "2014-12-29T13:56:16.000+0100", "_links": {
"base": "https://host.abc123.net/confluence",
"context": "/confluence",
"self": "host.abc123.net/confluence/rest/api/content/12345678/history"
}, "_expandable": {
"lastUpdated": ""
}}
I know that this page has 17 versions in the history through the browser interface. I can't seem to get anywhere by adding any kind of expand= to the query either.
The documentation for Confluence REST API tells me that this call should:
Returns a full JSON representation of the content's history
If I turn to the "normal" REST API call to retrieve content, I can get some hint about the history in the version structure:
{"version": {
"by": {
"type": "known",
"profilePicture": {
"path": "/confluence/s/en_GB/5639/.../profilepics/default.png",
"width": 48,
"height": 48,
"isDefault": true
},
"username": "some.other#abc123",
"displayName": "Some Other",
"userKey": "userKeyGuidThingy"
},
"when": "2015-01-30T16:00:09.000+0100",
"message": "",
"number": 17,
"minorEdit": false
} }
I am very keen on retrieving the other versions, numbers 1 - 16, but I can't see how..
I'd be most grateful for any help to get me unstuck.. :)
Here is an example:
Request:
http://localhost:8090/rest/experimental/content/7965952/version?expand=content
Response:
{
"results": [
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:56:29.000+03:00",
"message": "more stuff",
"number": 6,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "current",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/display/S1/cla1",
"tinyui": "/x/AI15",
"self": "http://localhost:8090/rest/api/content/7965952"
},
"_expandable": {
"container": "/rest/api/space/S1",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/6"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:56:12.000+03:00",
"message": "stuff",
"number": 5,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965962",
"tinyui": "/x/Co15",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=5"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=5",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/5"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:39:28.000+03:00",
"message": "",
"number": 4,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965961",
"tinyui": "/x/CY15",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=4"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=4",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/4"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:39:12.000+03:00",
"message": "",
"number": 3,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965959",
"tinyui": "/x/B415",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=3"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=3",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/3"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:38:36.000+03:00",
"message": "",
"number": 2,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965957",
"tinyui": "/x/BY15",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=2"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=2",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/2"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:23:14.000+03:00",
"message": "",
"number": 1,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965955",
"tinyui": "/x/A415",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=1"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=1",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/1"
}
}
],
"start": 0,
"limit": 100,
"size": 6,
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version?expand=content",
"base": "http://localhost:8090",
"context": ""
}
}
this will get you all versions of a page with version messages
I found the way to get version number.
so If you go to https://confluence.yourdomain.com/rest/api/content/page_id(1234567)/history. You will get the following json response.
{
"previousVersion":{
"by":{
"type":"known",
"profilePicture":{
"path":"image/path",
"width":48,
"height":48,
"isDefault":true
},
"username":"username",
"displayName":"password",
"userKey":"userkey"
},
"when":"date-time",
"message":"",
"number":1,
"minorEdit":false
},
"lastUpdated":{
"by":{
"type":"known",
"profilePicture":{
"path":"image/path",
"width":48,
"height":48,
"isDefault":true
},
"username":"username",
"displayName":"password",
"userKey":"userkey"
},
"when":"date-time",
"message":"",
"number":2,
"minorEdit":false
},
"latest":true,
"createdBy":{
"type":"known",
"profilePicture":{
"path":"image/path",
"width":48,
"height":48,
"isDefault":true
},
"username":"username",
"displayName":"password",
"userKey":"userkey"
},
"createdDate":"userkey",
"_links":{
"base":"https://confluence.yourdomain.com",
"context":"",
"self":"https://confluence.yourdomain.com/rest/api/content/page_id/history"
}
}
From that response json just fetch the version number depends on the scripting language that you are using. For Python following the piece of code will fetch the version number.
version=requests.get(https://confluence.yourdomain.com/rest/api/content/page_id(1234567)/history)
version= version.json()
print version['lastUpdated']['number']
This will give you latest version number of the page.