How to get the value of a specific custom field (such as "author") through the `extra` field?

Calendar 👁️ 75

In AnQi CMS, the custom fields of documents are a reflection of its powerful flexibility, allowing us to add various unique attributes to content, thereby enabling more refined management and display of information.But for many developers and operations personnel, how to accurately obtain the values of these custom fields through the API is often a clear issue.Don't worry, Anqi CMS provides a clear path in API design, throughextraField, you can easily master this additional data.

UnderstandingextraField: treasure house of custom data.

When you make an API request to the Anqi CMS for details of a single document or a list of documents, the returned data will usually include a field namedextraa field that containsextraThe field, as the name implies, is a collection of 'additional' information, specifically used to store all the custom fields and their corresponding values that you configure for the document model in the background.It is an object type, whose internal structure is very intuitive and convenient for programming access.

To be specific,extraEach key inside the object corresponds to the form field name you set when creating custom fields in the AnQi CMS backend (field_name)。This key corresponds to a small object that contains three properties:

  • name:This is the Chinese name of the custom field for easy understanding.
  • valueThis is the actual content of the custom field filled in, which is the data you hope to obtain the most.
  • defaultIf the user does not fill in this field, it will display the default value set in the background.

How to get the value of a specific custom field? For example, 'author'

Assuming we are now to retrieve the author information of a document. In the Anqi CMS backend, you may have already added a named "author" to the article model, with the form field name ofauthorcustom field.

To obtain detailed information about this document, we usually usearchive/detailan interface. You can access the document throughIDor itsURL 别名(filename)to request this interface. For example, to request a document with ID 1:

GET {域名地址}/api/archive/detail?id=1

The data returned by the interface will be a JSON structure, wheredatathe object contains all the detailed properties of the document. Insidedatayou will findextrafields, which may look like this:

{
  "code": 0,
  "data": {
    "id": 1,
    "title": "欢迎使用AnqiCMS",
    // ... 其他常规字段 ...
    "extra": {
      "author": {
        "name": "作者",
        "value": "AnqiCMS",
        "default": ""
      },
      "certificate": {
        "name": "学历",
        "value": null,
        "default": null
      },
      "city": {
        "name": "城市",
        "value": "北京\n上海\n重庆\n广州\n天津",
        "default": "北京\n上海\n重庆\n广州\n天津"
      }
    },
    // ... 其他字段 ...
    "link": ""
  },
  "msg": ""
}

From the above example, we can clearly seeextrathere is aauthorkey. To get the actual name of the author, you just need to follow the data pathdata.extra.author.valueIt can be. In your programming language, it usually looks like thisresponse.data.extra.author.valueFor example, ifresponseIs the parsed JSON object, thenresponse.data.extra.author.valueIt will return"AnqiCMS".

Custom fields for document lists get applied

It is not only the details of a single document, when you accessarchive/listthrough an interface to obtain a list of document items, eachextraThe field will also contain its custom field information. This means you can easily display author, source, specific attributes, and other custom information directly in places like article lists, product display pages, etc., without needing to request details for each list item individually.

the way to access is witharchive/detailThe interface is completely the same. When traversing the document list, for each document object, you still access it according to the custom field name "form field call name".extraThe corresponding in the object.value.

Useful tips and precautions

  1. The field name is crucial: Be sure to remember the 'form field name' you defined in the backend custom field settings (field_nameThis is the unique identifier obtained through API programming. If forgotten, it can be obtained throughapi/module/detailinterface to get model details, which will list all custom fieldsfield_name.
  2. handle empty value situations: Not all documents will fill in all custom fields, or a field may not exist at all in some document models. Be sure to handle this in your code.extraCheck for null values in objects and their nested custom fields to avoid runtime errors. For example, before accessingdata.extra.author.valuefirst verifydata.extraDoes it exist anddata.extra.authorwhether it exists.
  3. Differentiatenameandvalue:extraEach custom field object under the field hasnameandvaluetwo properties.nameis the display name of the field (such as “author”), whereasvalueis the actual content you need (such as “AnqiCMS”).

By understanding and making good use ofextraField, Anqi CMS provides an extremely convenient way to manage and display a variety of content attributes, making your website or application content more profound and flexible.


Frequently Asked Questions (FAQ)

Q1: How do I know the form field name of a custom field if I don't know it?A1: You can confirm in two ways: first, log in to the Anqi CMS backend, go to “Content Management” -> “Model Management”, find the corresponding document model and click edit, where all custom fields and their “form field call names” under the model will be listed. Second, you can also callapi/module/detailInterface, pass in the model ID and find the custom field you want in the returneddata.fieldsarray, whose property is the corresponding call name.field_name.

Q2: Why is the one I getextraThe field is empty or does not contain the custom field I want?A2: This usually has several reasons:

1.  **文档未填写该字段**:如果该文档在编辑时,您在对应的自定义字段中留空了,那么 `extra` 中该字段的 `value` 就会是 `null`。
2.  **字段不属于该文档模型**:您可能试图获取的自定义字段并不属于当前文档所使用的模型。请检查后台模型配置。
3.  **接口类型**:只有 `archive/detail` 和 `archive/list` 这两个接口会在 `data` 中返回 `extra` 字段,其他接口如 `archive/prev` 或 `archive/next` 通常不包含此信息。

Q3:data.extra.your_field.nameanddata.extra.your_field.valueWhat is the difference? Which one should I use?A3:data.extra.your_field.nameThe one you set for this custom field in the background is returneddisplay name(for example, “author”)). Anddata.extra.your_field.valueThe field returned is the one that the user enters while editing the documentThe content actually filled in(For example "AnqiCMS"). In most cases, you would want to retrieve and display the content filled in by the user, so you should usedata.extra.your_field.value.

Related articles

How to display the `extra` object, how to access its `name` and `value`?

When using AnQiCMS to manage website content, the flexibility of custom fields in the document model is one of its highlights.These custom fields allow us to add unique properties for different types of documents (such as articles, products, etc.), greatly enriching the content dimensions.When obtaining document details or lists through the API, the information of these custom fields is cleverly encapsulated in the `extra` object of the returned data.

2025-11-09

What detailed information will the nested `category` object return?

When we explore the mysteries of content in AnQi CMS, we often need to obtain detailed information about the documents.The `archiveDetail` interface provides us with rich document data, and the nested `category` object is a frequently overlooked but extremely important repository of information.It is not just a simple classification ID, but a complete entity containing all the metadata of the classification, which provides great convenience for us to deeply understand the context of the document and to carry out refined content display.

2025-11-09

If the document is a product type, how can you get its `price` (price) and `stock` (stock) information?

In Anqi CMS, if you are managing documents of product types and need to obtain specific price (`price`) and stock (`stock`) information for these products, it is actually very direct and convenient.The design of AnQi CMS considers such needs, making these key data as one of the core attributes of the document, you can easily obtain them through several core interfaces.### Get the price and stock information of a single product document When you need to view the price and stock of a specific product, AnQi CMS provides the `archiveDetail` interface

2025-11-09

The value of the `status` field in the document details, for example 1, specifically indicates which display status the document has?

When using AnQi CMS to manage website content, you may encounter various technical parameters, one of which seems simple but is crucial is the `status` field in the document details.It acts like a 'switch' for the content, quietly controlling whether your article, product, or other information can be seen by visitors. Then, what does this `status` field specifically represent?In simple terms, it is an integer value used to mark the current display state of the document.

2025-11-09

What does it mean if an error code 1001 or 1002 occurs when getting the document details, and how to solve it?

When using AnQi CMS for website content management and development, we often use API interfaces to obtain various data, among which obtaining document details (`/api/archive/detail`) is very commonly used.When you call this interface, if you encounter system return codes 1001 or 1002, it usually indicates that the request was not successfully processed and a specific reason is given.Understanding the meaning and solutions of these error codes can help us more efficiently troubleshoot problems and ensure the normal display of website content.### Error Code 1001

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 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 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