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+"program-status-rollup-employee"&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+"program-status-rollup-employee"&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?

Hey @coreygans,

I think that when using curl you will need to escape some " with %22 as the same you did with escaping = with %3D

curl -u $user:$password http://localhost:8090/rest/api/content/search?cql=label%20%3D%20%22program-status-rollup-employee%22&expand=space

Hi @italo.qualisoni I actually do escape it, but just realized the the confluence form decoded it. Any other thoughts? Note that it works correctly in the browser, but when I call it from curl it omits the expand=space. Do I need to encode something in the expand=space?

Hi @coreygans,

Try escaping the ampersand with single quotes like
curl -u $user:$password http://localhost:8090/rest/api/content/search?cql=label%20%3D%20%22program-status-rollup-employee%22'&'expand=space. Without escaping ampersand, I would assume that the script will be run in the background, hence, the trailing expand=space will no longer be part of the curl request and will be treated like you are assigning space to variable expand.

I verified the above-mentioned behavior and it holds true, at least on my machine :slight_smile: If you’re using Windows cmd, I think there might be a different way of escaping ampersands.

Cheers,
Ian

2 Likes

Thank you @ianRagudo! Totally correct!

1 Like