首页 > 解决方案 > curl get is omitting json that is shown in the browser

问题描述

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?

标签: jsoncurlconfluence-rest-api

解决方案


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


推荐阅读