In the daily operation of AnQi CMS, we often encounter such needs: we have a document detail page URL visible on a website, such ashttps://en.anqicms.com/anqicmsWe hope to quickly obtain the complete API details of this document through programming, including its title, content, SEO information, etc.This CMS provides a very convenient and intuitive interface to meet this need.
To achieve this goal, we mainly rely on the 'Get Document Details Interface' provided by the security CMS/api/archive/detail)。This interface is designed to be very flexible, it not only supports querying through the unique numeric ID of the document, but also cleverly supports querying through the 'alias' in the URL of the documentfilenameorurl_token)Query. It is this feature that makes it simple to extract API information from the known document detail URL.
The core idea is like this:
Firstly, you need to identify your security CMS websitedomain address. For example, if your document detail page ishttps://www.yourdomain.com/your-article-alias, then your domain address ishttps://www.yourdomain.com.
其次,from the document detail URL you know, we need to extract the "URL alias" of the document.https://en.anqicms.com/anqicmsFor example, it is obvious that,anqicmsThis is the URL alias of the document. This alias is usually referred to as in the document management of Anqi CMS.url_tokenorfilename.
With the domain address and document alias, we can build API requests. The call address for the document detail interface is{域名地址}/api/archive/detailand it usesGETMethod. We will take the document alias we extract asfilenamepass it as a parameter to this API.
Therefore, forhttps://en.anqicms.com/anqicmsthe corresponding API request for this URL will be:
GET https://en.anqicms.com/api/archive/detail?filename=anqicms
After you send this GET request, the backend of Anqi CMS will handle this request and return a JSON formatted data packet.This packet will contain all the details of the document.codeField indicates whether the request is successful,msgField provides message description, and all the document data we care about will be encapsulated in,datafield in.
IndataField, where you can find the document's,id/title(Title),seo_title(SEO title),keywords(Keywords)、description(Summary), as well as the most importantdataObject, whose internalcontentfields are the detailed content of the document. In addition, there are such ascategory(Categorization information),images(Group photos),logo(Document Logo),thumbThumbnail and other rich data can help you fully understand and utilize the document information.
This method of obtaining document details through URL alias provides great convenience for dynamically rendering content on the front end, building custom applications, or performing data integration.You do not need to know the numeric ID of the document in advance, just extract the key part from the friendly URL that the user accesses.
It should be noted that in actual operation, please make sure to use the example in the{域名地址}Replace it with your actual website domain to ensure that the API requests are sent correctly to your security CMS instance.
Common Questions (FAQ)
1. If I only have the document's numeric ID, not the URL alias, can I still get its API details?
Of course, it can be. The "Get Document Details Interface" of Anqi CMS supports two methods of query: You can pass in the numeric ID of the document asidparameters, such ashttps://en.anqicms.com/api/archive/detail?id=1, with the same effect as usingfilenameThe parameters are the same. In most cases, if both are known, using ID will be slightly more direct.
2. Where is the actual content of the document in the API return data? I see many fields, but no main text.
The actual main text content of the document is usually nested indataThe sub-object of the field. Specifically, you need to finddata.data.contentthis path. For example, in the returned JSON, you will see something like"data": { "id": 1, "content": "<p>欢迎使用AnqiCMS</p>" }such a structure, where thecontentField is the main body of the document you are looking for.
3. If the URL structure of my document is complex, such ashttps://en.anqicms.com/category/sub-category/my-article-nameHow can I extractfilename?
通常情况下,auto CMS会将文档的URL别名(filenameorurl_token)放在URL路径的最后一段。对于https://en.anqicms.com/category/sub-category/my-article-name这种结构,其filename通常就是my-article-name. You can parse the URL path to get the last slash/The remainder to obtain it.If your website has enabled staticization and the rules are quite special, you may need to refer to your website's backend configuration to determine the actual location of the URL alias.