When using the AnQi CMS to manage website content, we often need to retrieve detailed information of 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.).AutoCMS 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 document IDs to easily obtain detailed information about documents in the Anqi CMS, making your content operation more efficient and automated.
Core Steps: How to get document details through API
To get the document details of the Anqi CMS, you need to use the "Get Document Details Interface" provided.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,{域名地址}This field needs to be replaced with the actual domain name of your website, for example,https://www.yourdomain.com/api/archive/detail.
The calling method of this interface isGETRequest, means you can access it directly through the browser or use the HTTP GET method to request data in the code.
Request parameters: ID and alias, flexible choice
To specify which document details you want to obtain, 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 类型,可选):如果您传入了
id,就不需要再传filename. But if you do not know the document ID, but know the document alias URL (usually the friendly name in the document link), you can also access it throughfilenameGet the document details. This is very useful in many scenarios, such as when you only know the short link of an article.
Remember,idandfilenameChoose either one, and entering one of them will successfully retrieve the information.
Please provide data sample:
Assuming you want to get the details of the document with ID:1Your request would be like this:{域名地址}/api/archive/detail?id=1
If you want to use an aliasanqicms-tutorialto retrieve the document, the request would be:{域名地址}/api/archive/detail?filename=anqicms-tutorial
Understand the data returned by the API
When you successfully call the interface, the CMS will return a JSON data packet containing all relevant information about the requested document. This data packet usually includes the following core parts:
code(int type):Error code. Usually0It indicates that the request was successful, and other non-zero values indicate that an error occurred.msg(string type):Error reason description. IfcodeIt is not0Here will be specific error information to help you troubleshoot the problem.data(object type):This is the core content of the document details. If the request is successful, this will be an object containing the various properties of the document; if the document does not exist or an error occurs, this field may benull.
data对象:文档信息的仓库
data对象内部包含了文档的各个方面,您可以从中提取出所需的信息:
文档的基本信息:
id: The unique ID of the document.title: Document title.description: Document summary.url_token:文档的URL别名。keywordsEnglish: Document keywords.
English: Rich content presentation:
data.contentEnglish: This is the actual content details of the document, usually returned in HTML string format, convenient for you to render directly to the page.logo:The document's logo image address.thumb:The document's thumbnail image address.images:An array of strings, containing the document's group image (multiple images) addresses.
Important operational metadata:
seo_title:The SEO title of the document, used for search engine optimization.viewsThe number of views of the document.comment_count:The number of comments on the document.created_time:The timestamp of the document's publication.updated_time:The last update timestamp of the document.flag:The recommended attributes of the document, such as headline, recommendation, slideshow, etc.
Associated information with custom extension:
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 the custom fields you set in the AnQi CMS backend model. For example, if you add a "author" field to the article model, the information of the author will be included here, and the structure is usuallykey => itemwhere,nameThis is the field name.valueThis is 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": ""
}
Actual application scenarios
Obtaining document details through document ID is one of the foundations of the Anqi CMS API, and its application scenarios are very extensive:
- Build highly customized detail pages:You can fully control the display of documents on the front end and are no longer limited by preset templates.
- Develop cross-platform applications:Whether it is a PC terminal, H5, mini-program, or native APP, unified document data sources can be obtained through this interface.
- [en] SEO Optimization:get
seo_title/keywordsanddescriptionThe information, etc., can be dynamically set on the page SEO metadata in the front-end. - Data analysis and content recommendation:Combine
views/comment_countetc., allowing you to build a more intelligent content recommendation system or conduct data analysis. - Content aggregation and distribution:Quickly obtain detailed information of a large number of documents, used for building content aggregation platforms or distributing content to third-party platforms.
Tips for error handling
When using the API, understanding common error codes can help you locate issues faster: English
code: 0: Everything is normal, the data is beingdatafield in.code: -1: General error, the specific reason will be displayed onmsgField, for example, "The 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 user credentials, this error will occur.code: 1002: Unauthorized. Even if logged in, access to some documents may be denied due to insufficient permissions.
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.
Common Questions (FAQ)
Q1: If I pass both parameters at the same time,idandfilenamewhich one will the system use first?
A1:According to the document of Anqi CMS, if you pass both parameters at the same time,idandfilenamethe system will usually process the second one first.id参数。To avoid confusion and ensure clarity in the request, it is recommended that you only pass one parameter, choosing the one that is most convenient or most clear to you.
Q2:If the requested document does not exist, what will the API return?
A2:If the requested document ID or filename does not exist, the API will return acoderesponse for-1The status code, andmsga similar prompt message such as "Document not found" should be provided in thedatafield is usuallynullor an empty object. In your program, you should handlecodeanddataField judgment is made to properly handle the case where the document does not exist.
Q3: Can I only get the title and summary of the document through this interface instead of all fields?
A3:The interface for obtaining document details is designed to return all available detailed information about the document in one go.This means you cannot directly control to return only part of the fields via parameters.If you only need a document's title, summary, and other limited information, and do not need the full document content, you can obtain the complete data on the front-end or back-end, and then extract or filter the required fields according to your needs for display./api/archive/listMaybe it is more suitable,