Class ContentResource


  • public class ContentResource
    extends Object
    REST wrapper for the ContentService. Provides methods for finding, creating, modifying and deleting Content.
    • Method Detail

      • getContentById

        @PublicApi
        public Content getContentById​(ContentId id,
                                      List<ContentStatus> statuses,
                                      Integer version,
                                      String expand)
                               throws ServiceException

        Returns a piece of Content.

        Example request URI(s):

        • http://example.com/confluence/rest/api/content/1234?expand=space,body.view,version,container
        • http://example.com/confluence/rest/api/content/1234?status=any
        Parameters:
        id - the id of the content
        statuses - list of Content statuses to filter results on. Default value: [current]
        expand - A comma separated list of properties to expand on the content. Default value: history,space,version We can also specify some extensions such as extensions.inlineProperties (for getting inline comment-specific properties) or extensions.resolution for the resolution status of each comment in the results
        Returns:
        a JSON representation of the content, or a 404 NOT FOUND if there is no content with the given id or if the user is not permitted.
        Throws:
        ServiceException
      • createContent

        @PublicApi
        public Content createContent​(Content content,
                                     ContentStatus status,
                                     String expand)
                              throws ServiceException

        Creates a new piece of Content or publishes the draft if the content id is present.

        For the case publishing draft, a new piece of content will be created and all metadata from the draft will be transferred into the newly created content.

        Parameters:
        content - new content to be created
        expand - A comma separated list of properties to expand on the content. Default value: history,space,version
        Returns:
        a JSON representation of the content, or a 404 NOT FOUND if there is no content with the given id or if the user is not permitted.
        Throws:
        ServiceException
      • getContent

        @PublicApi
        public PageResponse<Content> getContent​(String type,
                                                String spaceKey,
                                                String title,
                                                List<ContentStatus> statuses,
                                                String postingDay,
                                                String expand,
                                                int start,
                                                int limit,
                                                @Context
                                                javax.ws.rs.core.UriInfo uriInfo)
                                         throws ServiceException

        Returns a paginated list of Content.

        Example request URI(s):

        • http://example.com/confluence/rest/api/content?spaceKey=TST&title=Cheese&expand=space,body.view,version,container
        • http://example.com/confluence/rest/api/content?type=blogpost&spaceKey=TST&title=Bacon&postingDay=2014-02-13&expand=space,body.view,version,container
        Parameters:
        type - the content type to return. Default value: page. Valid values: page, blogpost.
        spaceKey - the space key to find content under.
        title - the title of the page to find. Required for page type.
        statuses - list of statuses the content to be found is in. Defaults to current is not specified. If set to 'any', content in 'current' and 'trashed' status will be fetched. Does not support 'historical' status for now.
        postingDay - the posting day of the blog post. Required for blogpost type. Format: yyyy-mm-dd. Example: 2013-02-13
        expand - a comma separated list of properties to expand on the content. Default value: history,space,version.
        start - the start point of the collection to return
        limit - the limit of the number of items to return, this may be restricted by fixed system limits
        uriInfo - (injected) information about the request URI
        Returns:
        a JSON representation of the list of content, or a 404 NOT FOUND if the user is not permitted.
        Throws:
        ServiceException
      • scanContent

        @PublicApi
        public PageResponse<Content> scanContent​(String spaceKey,
                                                 List<ContentStatus> statuses,
                                                 String expand,
                                                 int limit,
                                                 String cursor,
                                                 @Context
                                                 javax.ws.rs.core.UriInfo uriInfo)
                                          throws ServiceException

        Returns a paginated list of Content.

        Example request URI(s):

        • http://example.com/confluence/rest/api/content/scan?spaceKey=TST&limit=100&expand=space,body.view,version,container
        • http://example.com/confluence/rest/api/content/scan?limit=100&expand=space,body.view,version,container
        Parameters:
        spaceKey - the space key to find content under.
        statuses - list of statuses the content to be found is in. Defaults to current is not specified. If set to 'any', content in 'current', 'draft' and 'trashed' status will be fetched.
        expand - a comma separated list of properties to expand on the content. Default value: history,space,version.
        limit - the limit of the number of items to return, this may be restricted by fixed system limits
        cursor - the identifier which is used to skip results from a previous query when paginating. Cursor is empty in first request, to move forward or backward use cursor provided in response.
        uriInfo - (injected) information about the request URI
        Returns:
        a JSON representation of the list of content, or a 404 NOT FOUND if the user is not permitted.
        Throws:
        ServiceException
        Since:
        7.18
      • search

        @PublicApi
        public PageResponse<Content> search​(String cql,
                                            String cqlcontext,
                                            String expand,
                                            int start,
                                            int limit,
                                            @Context
                                            javax.ws.rs.core.UriInfo uriInfo)

        Fetch a list of content using the Confluence Query Language (CQL). See: Advanced searching using CQL

        For example:

        Example request URI(s):

        • http://localhost:8080/confluence/rest/api/content/search?cql=creator=currentUser()&cqlcontext={%22spaceKey%22:%22TST%22, %22contentId%22:%2255%22}
        • http://localhost:8080/confluence/rest/api/content/search?cql=space=DEV%20AND%20label=docs&expand=space,metadata.labels&limit=10
        Parameters:
        cql - a cql query string to use to locate content
        cqlcontext - the context to execute a cql search in, this is the json serialized form of SearchContext
        expand - a comma separated list of properties to expand on the content.
        start - the start point of the collection to return
        limit - the limit of the number of items to return, this may be restricted by fixed system limits
        uriInfo - (injected) information about the request URI
        Returns:
        a JSON representation of the list of content, or a 404 NOT FOUND if the user is not permitted.
        Throws:
        ServiceException
      • getHistory

        @PublicApi
        public History getHistory​(ContentId contentId,
                                  String expand)
                           throws ServiceException

        Returns the history of a particular piece of content

        Example request URI(s):

        • http://example.com/confluence/rest/api/content/1234/history
        Parameters:
        contentId - the id of the content
        expand - the properties on content history to expand
        Returns:
        a JSON representation of the content history
        Throws:
        ServiceException
      • getMacroBodyByHash

        @Deprecated
        @PublicApi
        public MacroInstance getMacroBodyByHash​(ContentId contentId,
                                                int versionId,
                                                String hash)
                                         throws ServiceException

        Returns the body of a macro (in storage format) with the given hash. This resource is primarily used by connect applications that require the body of macro to perform their work.

        The hash is generated by connect during render time of the local macro holder and is usually only relevant during the scope of one request. For optimisation purposes, this hash will usually live for multiple requests.

        Collecting a macro by its hash should now be considered deprecated and will be replaced, transparently with macroIds. This resource is currently only called from connect addons which will eventually all use the getContentById(com.atlassian.confluence.api.model.content.id.ContentId, java.util.List, Integer, String) resource.

        To make the migration as seamless as possible, this resource will match macros against a generated hash or a stored macroId. This will allow add ons to work during the migration period.

        Parameters:
        contentId - a string containing the id of the content
        versionId - the version of the content which the hash belongs
        hash - the macroId to find the correct macro
        Returns:
        the raw macro body in storage format
        Throws:
        ServiceException
      • getMacroBodyByMacroId

        @PublicApi
        public MacroInstance getMacroBodyByMacroId​(ContentId contentId,
                                                   int versionId,
                                                   String macroId)
                                            throws ServiceException

        Returns the body of a macro (in storage format) with the given id. This resource is primarily used by connect applications that require the body of macro to perform their work.

        When content is created, if no macroId is specified, then Confluence will generate a random id. The id is persisted as the content is saved and only modified by Confluence if there are conflicting IDs.

        To preserve backwards compatibility this resource will also match on the hash of the macro body, even if a macroId is found. This check will become redundant as pages get macroId's generated for them and transparently propagate out to all instances.

        Parameters:
        contentId - a string containing the id of the content
        versionId - the version of the content to search
        macroId - the macroId to find the correct macro
        Returns:
        the raw macro body in storage format
        Throws:
        ServiceException
        Since:
        5.8
      • update

        @PublicApi
        public Content update​(ContentId contentId,
                              Content content,
                              ContentStatus status,
                              ContentDraftService.ConflictPolicy conflictPolicy)
                       throws ServiceException

        Updates a piece of Content, including changes to content status

        To update a piece of content you must increment the version.number, supplying the number of the version you are creating. The title property can be updated on all content, body can be updated on all content that has a body (not attachments). For instance to update the content of a blogpost that currently has version 1:

        PUT /rest/api/content/456

        
              {
                 "version":{
                     "number": 2
                 },
                 "title":"My new title",
                 "type":"page",
                 "body":{
                      "storage":{
                         "value":"<p>New page data.</p>",
                         "representation":"storage"
                    }
                 }
              }
         

        To update a page and change its parent page, supply the ancestors property with the request with the parent as the first ancestor i.e. to move a page to be a child of page with ID 789:

        PUT /rest/api/content/456

        
              {
                 "version":{
                     "number": 2
                 },
                 "ancestors": [{"id":789}],
                 "type":"page",
                 "body":{
                      "storage":{
                         "value":"<p>New page data.</p>",
                         "representation":"storage"
                    }
                 }
              }
         

        Changing status

        To restore a piece of content that has the status of trashed the content must have it's version incremented, and status set to current. No other field modifications will be performed when restoring a piece of content from the trash.

        Request example to restore from trash: {"id": "557059","status": "current","version": {"number": 2}}

        If the content you're updating has a draft, specifying status=draft will delete that draft and the body of the content will be replaced with the body specified in the request.

        Request example to delete a draft:

        PUT: http://localhost:9096/confluence/rest/api/content/2149384202?status=draft

        
             {
                "id":"2149384202",
                "status":"current",
                "version":{
                   "number":4
                },
                "space":{
                   "key":"TST"
                },
                "type":"page",
                "title":"page title",
                "body":{
                   "storage":{
                      "value":"<p>New page data.</p>",
                      "representation":"storage"
                   }
                }
             }
         

        Updating a draft is not currently supported.

        Parameters:
        contentId - the ID of the content to be updated
        content - the new content
        status - the existing status of the content to be updated.
        Returns:
        a JSON representation of an updated content, or a 400 BAD REQUEST if no space or no content type, or setup a wrong version type set to content, or status param is not draft and status content is current or a 404 NOT FOUND if can not find draft with current content when status param is draft and content status is current
        Throws:
        ServiceException
      • delete

        @PublicApi
        public javax.ws.rs.core.Response delete​(ContentId contentId,
                                                ContentStatus status)
                                         throws ServiceException
        Trashes or purges a piece of Content, based on its ContentType and ContentStatus.

        There are three cases:

        • If the content is trashable and its status is ContentStatus.CURRENT, it will be trashed.
        • If the content is trashable, its status is ContentStatus.TRASHED and the "status" query parameter in the request is "trashed", the content will be purged from the trash and deleted permanently.
        • If the content is not trashable it will be deleted permanently without being trashed.
        Parameters:
        contentId - the id of the content
        status - the status of the content to be deleted
        Throws:
        ServiceException