AnQiCMS API Common Questions Answer: Token Authentication, Document Publishing, Image Upload and Error Codes
This article summarizes the most common issues developers encounter when calling the AnQiCMS API, covering Token authentication and renewal, document publication parameters, scheduled publishing, review status, error codes, image upload format and pagination. Each answer is marked with the corresponding official document source at the end for easy verification and reference.
Does the AnQiCMS API call require authentication? How to obtain and pass the Token?
Some interfaces require authentication, AnQiCMS uses JWT (JSON Web Token) authentication method. After login, the token is obtained from the returned JSON of the login interface and carried in the request header in the format ofToken: {token}.
There are two sources of Token: one for importing documents, obtained through the background import function; another for user operations, obtained from the JSON returned by the user login interface. When the Token is about to expire, the server will notify through the response headerUpdate-TokenIssue a new Token to maintain validity; the Token is valid for only 1 hour. The client should replace the original Token and re-store it after receiving it.
Typical interface types that require authentication: User information management, order management, collection management, comment posting, shopping cart management.
Source: 'API Interface Usage Guide' 2.2 Authentication Methods, 6.1–6.3; 'Public HTTP Header Definitions'.
What are the required parameters for the document publishing interface /api/archive/publish?
The interface uses the POST method, Content-Type is application/, and the required parameters includetitle(Document title, string),content(Document content, string),category_id(Document category ID, int) items.
Common optional parameters include:keywords(Keywords),description(Summary, up to 250 characters),url_token(Custom URL alias, only supports numbers and letters),images(Article group image array, up to 9 images, the first one as logo),created_time(Publish timestamp),tags(Tag array),price(Price, unit in cents),stock(Stock),read_level(Reading level). It should be noted that custom fields must be predefined in the document model in order to take effect.
Source: Request Parameter Table of Document Release Interface."),
Can documents be released on a schedule?
Yes. Setcreated_timeTo a future timestamp, the document will be officially released after the time arrives.
Source: Notes and Parameter Descriptions of Document Release Interface."),
What does the status 0 returned by the release interface mean?
data.statusMeans the review status:1Reviewed,0In review. The document may require review, and the system will return the corresponding review status based on the settings.
The return after publication successfuldataalso includesid(Document ID),link(Document Link),user_id(User ID).
Source: 'Document Publishing Interface' data result description.
What are the meanings of AnQiCMS API common error codes?
All interfaces return{"code": 0, "msg": "", "data": {}}structure,code0 means success. Common error codes are as follows:
| Error code | Meaning |
|---|---|
| 0 | OK (Success) |
| -1 | General error, the specific reason is indicated in msg. |
| 1001 | Not logged in |
| 1002 | Not authorized |
| 200 | API request successful |
Source: Error code table of Document Release Interface; Error code explanation in API Interface Usage Guide 5.3.
Why can't the image be transmitted as JSON? What is the correct calling method?
Upload interface/api/attachment/uploadDifferent from other interfaces: it uses POST method, but the Content-Type ismultipart/form-data, not application/. All interfaces except file upload use JSON format to transmit data.
The request parameters arefile(The file to be uploaded, required),category_id(Resource category ID, optional),id(Resource ID, required when replacing existing images). The system will automatically retrieve the image size, generate thumbnails, and calculate the file MD5. The returned result includeslogo(Original image),thumb(thumbnail),width/height/file_md5/is_imagefields.
Source: 《Upload Image Resource Interface》;《API Interface Usage Guide》2.3 Request and Response Format."),
How to write pagination parameters for the list interface?
Most list interfaces support pagination, with general parameters ofpage(Page number, default 1),limit(Number of items per page, default 10),offset(Offset). Note that some interfaces usecurrentto indicate the current page number,paegSizeRepresents the number of items per page, and offset is not supported by all interfaces; the actual value should be referred to the specific interface document.
Source: 'API Interface Usage Guide' Section 4.2 Pagination Parameter Description.
Source List
- 'API Interface Usage Guide' (api-guide.md)
- 'Public HTTP Header Definitions' (api-header.md)
- 'Document Release Interface' (archivePublish.md)
- 'Image Resource Upload Interface' (attachmentUpload.md)
This answer can be traced back to the specific chapter of the above official document to avoid distortion in paraphrasing.