How to use AnQi CMS API to check if a specific document has been paid before viewing?

Calendar 78

When building and operating modern websites, especially when your platform involves quality content or exclusive resources, how to effectively manage content access permissions is a core issue.AnQiCMS (AnQiCMS) provides a powerful and flexible API interface, allowing you to precisely control the viewing conditions of documents, including determining whether a specific document requires payment and whether the user has completed the payment.

We will discuss how to use the API provided by AnQiCMS to check if a specific document has been paid for before viewing, to ensure that your paid content is properly protected.

Define the paid attributes of the document: Get document details

Before determining whether the user has paid, we first need to know whether the target document itself is set as paid content. Anqi CMS document detail interface/api/archive/detailIt can help us obtain detailed information about the document, including the price information of the document.

You can send a GET request to{域名地址}/api/archive/detailand include the document'sid(Or)filename) as a parameter to get the document details. For example,GET {域名地址}/api/archive/detail?id=123.

In the returned data, you will find a field namedprice. The value of this field represents the price of the document, unit is 'points'.

  • IfpriceThe value is0This indicates that the document is free content, which can be viewed directly by any user without payment verification.
  • Ifpriceis greater than0This indicates that this is a paid document. At this point, we need to further determine whether the current user has paid for this document.

By this step, we can effectively avoid unnecessary payment status checks for free documents, optimize system resources and response time.

Check if the user has paid: Verify order interface

Once the document is confirmed as paid content, the next step is to verify whether the current user has completed the payment for the document. AnQi CMS provides a dedicated interface for this: /api/archive/order/check.

You also need to send a GET request to{域名地址}/api/archive/order/checkand pass the document you want to checkidFor example,GET {域名地址}/api/archive/order/check?id=123.

The response of this interface is very direct:

  • If the returned data containsdataField istrueThis indicates that the currently logged-in user has paid for this document and is allowed to view the full content of the document.
  • IfdataField isfalseThis means that the current user has not paid. At this point, you can show the user the purchase options and guide them through the payment process.

It is worth noting that this interface requires the user to be logged in. If the user attempts to access paid content without being logged in or if their session token has expired, the API may return1001(Not logged in) or1002etc. error codes, you need to guide the user to log in according to these error codes.

Combined use to implement content permission management

Combine the above two APIs, and you can build a complete and flexible paid content access control logic:

  1. When the user tries to access a document, the first call is made to/api/archive/detailGet the detailed information of the document.
  2. Check the returned data forpriceField:
    • IfpriceWith0, directly display the document content.
    • Ifpricegreater than0, then the document is paid content and payment verification is required.
  3. Next, call/api/archive/order/checkPass the document inid.
  4. Based on/api/archive/order/checkreturneddataField:
    • IfdataWithtrueMeans the user has paid, display the document content.
    • IfdataWithfalseMeans the user has not paid, show the user a purchase prompt or a preview of the content.
    • If the API returns an unlogged/unauthorized error, guide the user to log in.

By this process, you can accurately provide your website visitors with a customized content access experience, which can protect your intellectual property rights, enhance users' willingness to pay, and maximize the value of content.

Frequently Asked Questions (FAQ)

Q1: If the document detail interface returns thepricefield is 0, do I need to call thearchiveOrderCheckinterface?A1: No need. IfpriceField 0 means that the document itself is free, and any user can view it without paying.Let it go, no need for additional payment status verification, which also helps optimize your system performance.

Q2: Call/api/archive/order/checkWhat result will be obtained when an interface, if the user is not logged in or not authorized?A2: In this case, the API will usually return an error code (such ascode: 1001indicating not logged in,code: 1002Indicates unauthorized, not a boolean valuetrueorfalseYou should catch these errors and guide users to log in according to the situation, or prompt them that they need to log in to purchase and view paid content.

Q3: In addition to paid pricing, does AnQiCMS support other types of document access restrictions, such as membership levels or password protection?A3: Yes, AnQiCMS not only supports paid pricing, but also provides other access control methods. There may be in the document details.read_levelField (corresponding to user group or member level), and existsarchivePasswordCheckThe interface is used to verify the document password. You can use these fields and interface to build a more complex document access permission system based on the payment status.

Related articles

How to get the link and title of the 'previous' or 'next' document by using the `id` of the current document through other interfaces?

In content-based websites, users often want to be able to easily navigate from the current article to the previous or next article. This continuous reading experience is crucial for improving user satisfaction and the website's PV (page views).AnQiCMS (AnQiCMS) provided us with a simple and efficient API interface to implement this function, allowing developers to easily integrate "previous/next" navigation on the article detail page.### Subtly Utilize API, Build Article Navigation AnQi CMS provides a very intuitive interface for obtaining the previous and next articles

2025-11-09

Does the data structure returned by the document detail interface change for different types of documents (such as articles and products)?

When building a website with AnQiCMS, we often need to obtain detailed information of various documents through the API interface.The `archive/detail` interface is the key to obtaining the details of a single document.Many developers and content operators may be curious, whether the data structure returned by this interface is different for different types of documents, such as ordinary articles, news, or product information on e-commerce websites.The answer is: it has both unity and high flexibility.First, Anqi CMS is in design

2025-11-09

How to ensure the uniqueness of document URL alias queries to avoid ambiguity?

When using AnQi CMS for content management, URL aliases (also known as URL Tokens) are a key component for building user-friendly and SEO-optimized websites.It not only makes your page address more readable, but also helps search engines better understand the content topic.However, it is particularly important to ensure the uniqueness of the document when querying through these URL aliases, otherwise it may cause the system to identify confusion, users to access incorrect pages, and even affect the SEO performance of the website.

2025-11-09

Does the document detail interface directly provide the detailed content of the document's category (`category.content`)?

When using AnQi CMS for website development or content integration, it is often necessary to obtain documents and their related information.One of the common questions is: When getting the details of a document, can we also get the detailed content of the category to which the document belongs, especially fields like `category.content`?According to the documents provided by AnQi CMS, we can clearly find the answer.To be direct, **yes, the AnQi CMS document detail interface (`/api/archive/detail`) indeed provides detailed content of the document's category

2025-11-09

How can I verify the password submitted through the API to obtain the document content if the document is protected by a password?

In Anqi CMS, content management not only covers the regular article publishing and display, but also provides flexible mechanisms to protect sensitive or exclusive content.When you need to allow users to access specific document content by entering a password, Anqicms provides a clear API interface to implement this function.This is very useful for building paid content, VIP areas, or internal material sharing scenarios.### Core Function: Document Password Verification API

2025-11-09

Does the `user_id` field in the document details indicate the document publisher or author ID?

When managing website content in AnQi CMS, we often encounter various data fields, among which the `user_id` field is a common and easily questionable identifier.When we retrieve document details from Anqi CMS, what does this `user_id` represent, the publisher or the author?To clearly understand this point, we need to analyze the data structure returned by the document interface.Firstly, from the `archiveDetail.md` document to get the API return parameters of the document details view

2025-11-09

How to use the `msg` field for precise error checking when the document detail interface returns `code: -1`?

Guide to troubleshooting when the AnQiCMS document detail interface returns `code: -1` When using AnQiCMS for website content management, we often use the provided API interface to retrieve or manipulate data.When calling the document detail interface (for example, `/api/archive/detail`), if the returned result contains a `code` field of `-1`, this usually means that the request was not successful, and an error occurred during the server-side processing.In such a situation, many users may feel confused

2025-11-09

How to use the `module_id` in the document details to query all the filterable parameter fields under the model?

In AnQi CMS, in order to better organize and display content, we often use document models and custom fields.When you want to provide a more flexible filtering function for documents under a specific model, for example, to search based on the attributes of a document such as 'city' or 'education', you need to know how to obtain these filterable parameter fields. This is usually a two-step process: first, we need to determine the model ID of the target document (`module_id`), which is the key to connecting the document with the model definition; then

2025-11-09