How can you get the document details of Anqi CMS by document ID?

Calendar 👁️ 75

When using Anq CMS to manage website content, we often need to retrieve detailed information about specific documents from the backend, whether it is to display content on custom pages or integrate data into other systems (such as mini-programs, mobile applications, etc.).AnQi CMS provides a powerful and flexible API interface, one of the core features of which is to obtain specific document details through the document ID.

Today, let's delve into how to use the document ID to easily obtain the document details of AnQi CMS, making your content operation more efficient and automated.

Core steps: How to obtain document details through the API

To obtain the document details of Anqi CMS, you need to use the "Get Document Details Interface" provided by it.This is like giving CMS a house number (document ID), and it will tell you all the public information in that house (document).

API call address and request method:

You can access this interface through the following address:{域名地址}/api/archive/detail

Please note,{域名地址}Replace with your actual website domain, for examplehttps://www.yourdomain.com/api/archive/detail.

The calling method of this interface isGETRequest, meaning you can access it directly through the browser or request data using the HTTP GET method in your code.

Request parameters: ID and alias, flexible selection.

To specify the details of the document you want to retrieve, you need to provide a parameter. Anqi CMS provides two very flexible options in this regard:

  • id (int type, required):This is the unique numeric identifier of the document in the system. If you know the document ID, you can enter it directly.
  • filename (string type, optional):If you have enteredid, you do not need to pass it againfilenameBut if you do not know the document ID, but know the document URL alias (usually the friendly name in the document link), you can also access it throughfilenameTo get the document details. This is very useful in many scenarios, for example, if you only know the short link of a news article.

Remember,idandfilenameYou only need to choose one, entering either one will successfully retrieve the information.

Sample data request:

Suppose you want to get the details of the document with ID:1The request would look like this:{域名地址}/api/archive/detail?id=1

If you want to use an aliasanqicms-tutorialTo get the document, the request would be:{域名地址}/api/archive/detail?filename=anqicms-tutorial

Understand the data returned by the API

After you successfully call the interface, Anqi CMS will return a JSON formatted data packet containing all the relevant information of the document you requested. This data packet usually includes the following core parts:

  • code(integer type):Error code. Usually0Indicates a successful request, other non-zero values indicate an error occurred.
  • msg(string type):Error reason description. Ifcodeis not0Here will provide specific error information to help you troubleshoot.
  • data(object type):This is the core content of the document details. If the request is successful, this will be an object containing various properties of the document; if the document does not exist or an error occurs, this field may benull.

dataObject: the treasure trove of document information

dataThe object contains all aspects of the document, from which you can extract the information you need:

  1. Basic information of the document:

    • id: The unique ID of the document.
    • title: The document title.
    • description: Document description.
    • url_token: The URL alias of the document.
    • keywords: Document keywords.
  2. Rich content presentation:

    • data.content: This is the actual content details of the document, usually returned as an HTML string, for direct rendering on the page.
    • logo: The document's logo image address.
    • thumb: The document's thumbnail image address.
    • images: A string array containing the document's group image (multiple images) addresses.
  3. Important operational metadata:

    • seo_title: The SEO title of the document, used for search engine optimization.
    • views: Document's view count.
    • comment_count: The number of comments in the document.
    • created_time: Document release timestamp.
    • updated_time: The last update timestamp of the document.
    • flag: The recommended attributes of the document, such as headline, recommendation, slideshow, etc.
  4. : Associated information and custom extensions.

    • categoryThis is a nested object that contains detailed information about the document's category, such as category ID, category name, category alias, etc., allowing you to easily obtain the category context.
    • extraThis is a very powerful field, which will display according to the custom field you set in the Anqicms backend model. For example, if you add an 'author' field to the article model, then this will include the author's information, the structure is usuallykey => itemof whichnameIs the field name,valueIs the value entered.

Return data example (simplified):

{
  "code": 0,
  "data": {
    "id": 1,
    "title": "欢迎使用AnqiCMS",
    "seo_title": "",
    "url_token": "anqicms",
    "keywords": "",
    "description": "欢迎使用AnqiCMS",
    "views": 1338,
    "logo": "https://en.anqicms.com/uploads/202012/7/bd36c37ef742c7be.webp",
    "thumb": "https://en.anqicms.com/uploads/202012/7/thumb_bd36c37ef742c7be.webp",
    "created_time": 1607308159,
    "category": {
      "id": 1,
      "title": "AnqiCMS帮助",
      "url_token": "goruning",
      "content": "<p>欢迎使用AnqiCMS</p>"
    },
    "data": {
      "content": "<p>欢迎使用AnqiCMS</p>"
    },
    "extra": {
      "author": {
        "name": "作者",
        "value": "AnqiCMS",
        "default": ""
      }
    }
  },
  "msg": ""
}

Application scenarios in practice

Obtaining document details through document ID is one of the cornerstones of Anqi CMS API, and its application scenarios are very extensive:

  • Build highly customized detail pages:You can fully control the way documents are displayed on the front end, no longer limited by preset templates.
  • Develop cross-platform applications:Whether it is PC terminal, H5, mini-program or native APP, unified document data source can be obtained through this interface.
  • SEO optimization:Obtainseo_title/keywordsanddescriptionInformation, can be dynamically set on the front-end page SEO metadata.
  • Data analysis and content recommendation:Combineviews/comment_countData, you can build a more intelligent content recommendation system or perform data analysis.
  • Content aggregation and distribution:Quickly obtain detailed information about a large number of documents, used to build content aggregation platforms or distribute content to third-party platforms.

Tips for error handling

When using the API, understanding common error codes can help you locate problems more quickly:

  • code: 0: Everything is normal, the data is in:datain the field.
  • code: -1: General error, the specific reason will be displayed in:msgField contains, for example, 'Document does not exist'.
  • code: 1001: Not logged in. If your CMS is set to require login to access documents, and you have not provided valid credentials, this error will occur.
  • code: 1002: Unauthorized. Even if you are logged in, you may not have sufficient permissions to access certain documents.

By understanding and making good use of this document detail interface, you can fully utilize the content management capabilities of Anqi CMS, bringing more flexible and powerful content display and interactive experience to your website or application.


Frequently Asked Questions (FAQ)

Q1: If I entered multipleidandfilename, which parameter will the system use first?

A1: According to the documentation of Anqi CMS, if you enter multipleidandfilename, the system will usually prioritize processingidParameter. To avoid confusion and ensure the clarity of the request, it is recommended to pass only one of the parameters, choosing the one that is most convenient or most explicit in your hand.

Q2: If the document I request does not exist, what will the API return?

A2: If the document ID or filename you request does not exist, the API will return acodeWith-1The status code, andmsgfield provides similar prompts like 'Document not found'. At this point,datafield is usuallynullor an empty object. In your program, you should handlecodeanddataField judgment is carried out to properly handle the situation where the document does not exist.

Q3: Can I get only the title and summary of the document through this interface, rather than all fields?

A3: The “Get Document Details Interface” is designed to return all available details of the document in one go.This means you cannot directly control the parameter to only return a part of the fields.If you only need the title, abstract, and other limited information of the document, without the full document content, you can get the complete data in front-end or back-end and then extract or filter the required fields according to your needs for display.If performance becomes a bottleneck, and you need a small amount of information from a large number of documents, then the "Get Document List Interface" (/api/archive/list)May be more suitable,“

Related articles

How to calculate the number of times a specific keyword appears in a string or array using the `count` filter in AnQiCMS templates?

During the template development process of AnQiCMS, we often need to perform dynamic data analysis or display of page content, such as counting the frequency of a keyword or checking the number of specific elements in a list.At this time, the `count` filter has become a very practical tool.It can help you quickly and efficiently calculate the number of times a specific keyword appears in a string or array, providing the possibility of flexible template presentation.--- ### `count` filter: Accurately count your content In short, `count`

2025-11-09

In AnQiCMS template, how to add a recommended icon to the article title based on the boolean state of the `item.Flag` attribute?

When managing website content in AnQiCMS, we often hope to highlight important articles through some intuitive visual elements, such as adding a prominent small icon to recommended content.This not only attracts the attention of visitors, but also helps them quickly find high-quality information on the website.It is fortunate that AnQiCMS has built-in `item.Flag` properties and a flexible template engine, making it very easy to implement this requirement.This article will discuss in detail how to use the `item.Flag` attribute status in the AnQiCMS template

2025-11-09

How to determine if the boolean value of a custom field in the AnQiCMS template is true and dynamically add a CSS class?

In AnQiCMS template development, we often need to adjust the display style of the page based on the specific attributes of the content.This includes dynamically adding CSS classes based on the boolean value of custom fields (i.e., true or false status), thus achieving a more flexible and expressive interface.AnQiCMS with its flexible content model design allows users to create various custom fields for different content types (such as articles, products).These custom fields greatly enrich the expression of content, enabling templates to be highly customized for different business needs.###

2025-11-09

How to combine `if` and `yesno` filters in AnQiCMS templates to display different prompts based on VIP status and expiration time?

In website operations, providing differentiated services and content prompts to different user groups is a key link in improving user experience and achieving business goals.Especially on websites with a VIP membership system, displaying personalized information based on the user's VIP status and even the expiration time of the membership can greatly enhance the user's sense of belonging and willingness to interact.AnQiCMS (AnQiCMS) relies on its flexible template engine and rich tags, filters, making everything simple and efficient.Today, let's discuss how to use the AnQiCMS template

2025-11-09

How to get the details of a document through the document URL alias (`filename`)?

In AnQi CMS, the document URL alias (`filename`) is a very practical feature, which not only makes your website URL more friendly and improves search engine optimization (SEO) effect, but also provides great convenience in content acquisition.When you need to obtain detailed information about a specific document through programming, AnQiCMS provides a simple and intuitive API interface.### Core Feature Revelation: Get Details Using Document URL Alias To get all details of the document through its URL alias

2025-11-09

If both `id` and `filename` parameters are provided, which one will the AnQi CMS document detail interface prioritize?

In AnQi CMS, getting document details is a very frequent operation in our daily operation.We usually request document data through the unique numeric identifier `id` or the user-friendly URL alias `filename`.

2025-11-09

What error message will the interface return if the document does not exist when getting the document details?

In the daily operation and development of Anqi CMS, we often need to retrieve website content through API interfaces, among which the 'Get Document Detail Interface' (`/api/archive/detail`) is undoubtedly one of the most frequently used ones.This interface allows us to retrieve the details of a specific article or product by document ID or URL alias (filename).However, during use, we are bound to encounter such situations: When the requested document does not exist in the system, what kind of error message will the interface return?This is for front-end page display

2025-11-09

What HTTP request methods does the AnQi CMS document detail interface support?

When building websites or developing various applications, we often need to obtain detailed information about articles or documents from a content management system (CMS).AnQiCMS (AnQiCMS) is a powerful content management platform and naturally provides such an interface, allowing developers to flexibly obtain various document content on the website.So, when we want to get the specific article through the document detail interface of Anqi CMS, which HTTP request method should we use?

2025-11-09