🚗 API Development Documentation
emlog pro version supports Interface (API) call functions. Developers can interact with the emlog system by calling APIs. For example: docking with article publishing software to achieve automatic article publishing; docking with WeChat Mini Programs to achieve diversified article display; docking with browser plugins to achieve more convenient note publishing functions, etc. Please refer to the following content for detailed interface instructions.
This document is written based on the latest version of emlog. Lower versions may not be compatible. Please upgrade to the latest version first and enable API in the background API settings page.
Interface Authentication
(1) API Key Authentication: Signature Authentication
- Request Method: POST/GET
- Parameters required for authentication:
| Parameter | Required | Description |
|---|---|---|
| req_sign | Yes | Interface signature, see the calculation signature rules below |
| req_time | Yes | Unix timestamp, php can use time() function to get, e.g.: 1651591816 |
Calculation Signature Rules
Concatenate the unix timestamp and API key and then perform md5 encryption. The API key can be found in the background System - Settings - API Settings page.
php code example:
$apikey = '******'; // API key, found in System - Settings - API Settings page
$req_time = time(); // unix timestamp, in seconds
$req_sign = md5($req_time . $apikey); // MD5 signature
(2) API Key Authentication: No Signature Authentication
Simple to use, but less secure than signature authentication. It is recommended to use with https.
- Request Method: POST/GET
- Parameters required for authentication:
| Parameter | Required | Description |
|---|---|---|
| api_key | Yes | API key, found in System - Settings - API Settings page |
(3) Cookie Authentication
The request needs to carry the login status cookie after the user logs in to the emlog system, which is used to identify the current login status and the logged-in user.
// emlog login status cookie looks like:
EM_AUTHCOOKIE_XXXXX=admin%7C0%7C2a12e9a651b7e44be3d2d3536f51eaaa; Path=/; HttpOnly;
API List
User Login
- User Login Interface
- Interface URL: https://yourdomain/admin/account.php?action=dosignin
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| user | Yes | Username, Email |
| pw | Yes | Password |
| persist | No | Remember me, keep login status (value: 1) |
| login_code | No | Image verification code |
| resp | Yes | Pass string "json" |
Return Result (with login success cookie)
{
"code": 0,
"msg": "ok",
"data": ""
}
User Registration
- User Registration Interface
- Interface URL: https://yourdomain/admin/account.php?action=dosignup
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| Yes | ||
| passwd | Yes | Password |
| repasswd | Yes | Repeat Password |
| login_code | No | Image verification code |
| mail_code | No | Email verification code |
| resp | Yes | Pass string "json" |
Return Result
{
"code": 1,
"msg": "Incorrect email format",
"data": ""
}
Retrieve Password: Verify Registration Email
- Retrieve Password: Verify Registration Email Interface
- Interface URL: https://yourdomain/admin/account.php?action=doreset
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| Yes | ||
| login_code | No | Image verification code |
| resp | Yes | Pass string "json" |
Return Result
{
"code": 0,
"msg": "ok",
"data": ""
}
Retrieve Password: Reset Password
- Retrieve Password: Reset Password Interface
- Interface URL: https://yourdomain/admin/account.php?action=doreset2
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| mail_code | Yes | Email verification code |
| passwd | Yes | Password |
| repasswd | Yes | Repeat Password |
| resp | Yes | Pass string "json" |
Return Result
{
"code": 0,
"msg": "ok",
"data": ""
}
Get Current Logged-in User Information
- Get Current Logged-in User Information Interface
- Interface URL: https://yourdomain/?rest-api=userinfo
- Request Method: GET
- Interface Authentication Method: [Cookie Authentication]
- Return Format: JSON
Request Parameters: None
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"userinfo": {
"uid": "1",
"nickname": "emer",
"role": "admin",
"photo": "../content/uploadfile/202303/ad7b1678085402.jpg",
"email": "",
"description": "",
"ip": "172.18.0.1",
"create_time": "1677640065"
}
}
}
Get User Information
- Get User Information Interface
- Interface URL: https://yourdomain/?rest-api=user_detail
- Request Method: GET
- Interface Authentication Method: [API Key Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | Yes | User ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"userinfo": {
"uid": 1,
"nickname": "emer",
"role": "admin",
"avatar": "http://localhost/content/uploadfile/202408/ad7b1723864764.jpg",
"description": "",
"create_time": 1723271947
}
}
}
Modify User Information
- Modify Current Logged-in User Information
- Interface URL: https://yourdomain/admin/blogger.php?action=update
- Request Method: POST
- Interface Authentication Method: [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| token | Yes | Backend token, get method: LoginAuth::genToken() |
| name | No | Nickname |
| description | No | Personal Description |
| username | No | Login Username |
Return Result
{
"code": 0,
"msg": "ok",
"data": ""
}
Change Password
- Change Current Logged-in User Password
- Interface URL: https://yourdomain/admin/blogger.php?action=change_password
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| token | Yes | Token, get method: LoginAuth::genToken() |
| new_passwd | No | New Password |
| new_passwd2 | No | Repeat New Password |
Return Result
{
"code": 0,
"msg": "ok",
"data": ""
}
Upload Avatar
- User Upload Avatar Interface
- Interface URL: https://yourdomain/admin/blogger.php?action=update_avatar
- Request Method: POST
- Request Body Format: Multipart Form Data (multipart/form-data)
- Interface Authentication Method: [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| image | Yes | Image submitted by form, PHP get: $_FILES["image"] |
Return Result
{
"code": 0,
"msg": "ok",
"data": "..\/content\/uploadfile\/202310\/ad7b1696580183.jpg"
}
Post Comment
- Post Comment Interface
- Interface URL: https://yourdomain/index.php?action=addcom
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| gid | Yes | Article ID |
| comname | Yes | Commenter Name |
| comment | Yes | Comment Content |
| commail | No | Commenter Email |
| comurl | No | Commenter Homepage URL |
| avatar | No | Commenter Avatar Image URL |
| imgcode | No | Image Verification Code |
| pid | No | Replied Comment ID |
| resp | Yes | Pass string "json" |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"cid": 4
}
}
Like Comment
- Like Comment Interface
- Interface URL: https://yourdomain/index.php?action=likecom
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| cid | Yes | Comment ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": ""
}
Comment List
- Get Article Comment List Interface
- Interface URL: https://yourdomain/?rest-api=comment_list
- Request Method: GET
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | Yes | Article ID |
| page | No | Comment pagination, requires enabling comment pagination function in backend settings |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"comments": {
"1": {
"cid": "1",
"gid": "1",
"pid": "0",
"top": "n",
"poster": "snow",
"uid": "0",
"comment": "stay hungry stay foolish",
"mail": "",
"url": "",
"ip": "",
"agent": "",
"hide": "n",
"date": "57 minutes ago",
"content": "stay hungry stay foolish",
"children": [],
"level": 0
}
},
"commentStacks": [],
"commentPageUrl": ""
}
}
Comment List - v2
- Get Article Comment List Interface
- Interface URL: https://yourdomain/?rest-api=comment_list_simple
- Request Method: GET
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | Yes | Article ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"comments": [
{
"cid": "1",
"gid": "1",
"pid": "0",
"top": "n",
"poster": "emlog",
"avatar": "http://localhost:8080/admin/views/images/avatar.svg",
"uid": "0",
"comment": "This is a system generated demo comment",
"mail": "",
"url": "",
"ip": "",
"agent": "",
"hide": "n",
"date": "2024-09-28 22:06",
"content": "This is a system generated demo comment",
"children": [
{
"cid": "2",
"gid": "1",
"pid": "1",
"top": "n",
"poster": "emer",
"avatar": "http://localhost:8080/",
"uid": "1",
"comment": "@emlog:This is a test comment",
"mail": "",
"url": "http://localhost:8080/",
"ip": "192.168.65.1",
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
"hide": "n",
"date": "3 seconds ago",
"content": "@emlog:This is a test comment",
"children": []
}
]
}
]
}
}
Like Article
- Like Article Interface
- Interface URL: https://yourdomain/index.php?action=addlike
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| gid | Yes | Article ID |
| name | No | Liker Name |
| avatar | No | Liker Avatar Image URL |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"id": 2
}
}
Cancel Article Like
- Article Cancel Like Interface, currently only supports logged-in users to cancel likes.
- Interface URL: https://yourdomain/index.php?action=unlike
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| gid | Yes | Article ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": {}
}
Like List
- Get Article Like List
- Interface URL: https://yourdomain/?rest-api=like_list
- Request Method: GET
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | No | Article ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"likes": [
{
"id": 1,
"gid": 1,
"poster": "snowsun",
"avatar": "https://oss.emlog.cn/avatar/avatar_y4LueUW71K3rIvxn.png?imageMogr2/thumbnail/200x",
"uid": 0,
"ip": "192.168.65.1",
"agent": "PostmanRuntime/7.41.2",
"date": "About 9 hours ago"
}
]
}
}
Article Post
- Article Post Interface, can be used for docking article publishing software
- Interface URL: https://yourdomain/?rest-api=article_post
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: [API Key Authentication] or [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| title | Yes | Title |
| content | Yes | Content |
| excerpt | No | Excerpt |
| cover | No | Cover |
| author_uid | No | Author User ID, can be viewed in the backend user management page |
| sort_id | No | Category ID, can be viewed in the backend category management page |
| tags | No | Tags, multiple separated by half-width commas, e.g.: PHP,MySQL |
| draft | No | Whether to publish as a draft, yes y, no n (default n) |
| post_date | No | Publish time, e.g.: 2022-05-03 23:30:16 |
| top | No | Sticky on homepage, yes y, no n, default n |
| sortop | No | Sticky in category, yes y, no n, default n |
| allow_remark | No | Allow comments, yes y, no n, default n |
| password | No | Access Password |
| link | No | Redirect link, if filled, it will jump directly to this address without displaying article content |
| field_keys[] | No | Custom field name, e.g. price: price |
| field_values[] | No | Custom field value, e.g. price value: 9.9 |
| auto_cover | No | Automatically get the image in the article as the cover, yes y, no n |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"article_id": 14
}
}
Article (Draft) Edit
- Article (Draft) Edit Interface
- Interface URL: https://yourdomain/?rest-api=article_update
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: [API Key Authentication] or [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | Yes | Article (Draft) ID |
| title | Yes | Title |
| content | No | Content |
| excerpt | No | Excerpt |
| cover | No | Cover |
| author_uid | No | Author User ID, can be viewed in the backend user management page |
| sort_id | No | Category ID, can be viewed in the backend category management page |
| tags | No | Tags, multiple separated by half-width commas, e.g.: PHP,MySQL |
| draft | No | Whether to publish as a draft, yes y, no n (default n) |
| post_date | No | Publish time, e.g.: 2022-05-03 23:30:16 |
Return Result
{
"code": 0,
"msg": "ok",
"data": ""
}
Article List
- Get Article List Interface
- Interface URL: https://yourdomain/?rest-api=article_list
- Request Method: GET
- Interface Authentication Method: No authentication required, no need to enable API
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| page | No | Page number, default starts from 1 |
| count | No | Number of articles per page, default follows backend settings |
| sort_id | No | Article Category ID, can be viewed in the backend category management page |
| keyword | No | Search keyword, only matches article title |
| tag | No | Article Tag |
| order | No | Article sorting, default sort by time descending, views: sort by views descending, comnum: sort by comment count descending |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"articles": [
{
"id": 31908,
"title": "Here is the article title",
"cover": "",
"url": "https://www.emlog.dev/post/31908",
"description": "Here is the article excerpt content",
"date": "2021-10-11 08:04:11",
"author_id": 3,
"author_name": "John Doe",
"author_avatar": "http://localhost/content/uploadfile/202408/ad7b1723864764.jpg",
"sort_id": 53,
"sort_name": "Category Name",
"views": 1,
"comnum": 0,
"like_count": 1,
"top": "y",
"sortop": "n",
"tags": [
{
"name": "emlog",
"url": "http://localhost:8080/?tag=emlog"
}
],
"need_pwd": "y",
"fields": {
"price": "9.9",
"color": "#ffffff"
}
}
],
"page": 1,
"total_pages": 3,
"has_more": true
}
}
Article Detail
- Get Article Detail Interface
- Interface URL: https://yourdomain/?rest-api=article_detail
- Request Method: GET
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | Yes | Article ID |
| password | No | Article password, used to access password-protected articles |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"article": {
"title": "Article Title",
"date": "2022-06-04 10:42:12",
"id": 54215,
"sort_id": -1,
"sort_name": "",
"type": "blog",
"author_id": "1",
"author_name": "snowsun",
"author_avatar": "http://localhost/content/uploadfile/202408/ad7b1723864764.jpg",
"content": "<p>Article Content</p>",
"excerpt": "<p>Here is the article excerpt</p>",
"cover": "Article Cover",
"views": 2,
"comnum": 0,
"like_count": 1,
"top": "n",
"sortop": "n",
"tags": [
{
"name": "emlog",
"url": "http://localhost/?tag=emlog"
}
],
"fields": {
"price": "9.9",
"color": "#ffffff",
}
}
}
}
Article Fields Description
| Parameter | Description |
|---|---|
| id | Article ID |
| title | Article Title |
| cover | Article Cover Image |
| url | Article URL |
| description | Article List Excerpt |
| description_raw | Article List Excerpt (markdown original) |
| content | Article Detail Content |
| content_raw | Article Detail Content (markdown original) |
| excerpt | Article Detail Excerpt |
| excerpt_raw | Article Detail Excerpt (markdown original) |
| date | Publish Date |
| author_id | Author ID |
| author_name | Author Nickname |
| author_avatar | Author Avatar |
| sort_id | Category ID |
| sort_name | Category Name |
| views | Read Count |
| comnum | Comment Count |
| like_count | Like Count |
| top | Sticky on Homepage y yes n no |
| sortop | Sticky in Category y yes n no |
| tags | Tags |
| need_pwd | Password Protected y yes n no |
| fields | Custom Fields |
Draft List
- Get Recently Published Draft List
- Interface URL: https://yourdomain/?rest-api=draft_list
- Request Method: GET
- Interface Authentication Method: [API Key Authentication] or [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| count | No | Get count |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"drafts": [
{
"id": 6,
"title": "Untitled",
"cover": "",
"excerpt": "",
"date": "2025-06-12 21:25:57",
"author_id": 1,
"author_name": "emer",
"author_avatar": "http://localhost:8080/admin/views/images/avatar.svg",
"sort_id": -1,
"sort_name": "",
"views": 0,
"comnum": 0,
"like_count": 0,
"top": "n",
"sortop": "n",
"tags": [],
"need_pwd": "n",
"fields": []
}
]
}
}
Draft Detail
- Get Draft Detail Interface
- Interface URL: https://yourdomain/?rest-api=draft_detail
- Request Method: GET
- Interface Authentication Method: [API Key Authentication] or [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| id | Yes | Draft ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"draft": {
"title": "This is a draft",
"date": "2025-06-12 21:25:57",
"id": 6,
"sort_id": -1,
"sort_name": "",
"author_id": 1,
"author_name": "emer",
"author_avatar": "http://localhost:8080/admin/views/images/avatar.svg",
"content": "This is a draft",
"excerpt": "This is a draft",
"cover": "",
"views": 1,
"comnum": 0,
"like_count": 0,
"top": "n",
"sortop": "n",
"tags": [],
"fields": []
}
}
}
Category List
- Get All Category List (including sub-categories) Interface
- Interface URL: https://yourdomain/?rest-api=sort_list
- Request Method: GET
- Interface Authentication Method: No authentication required
- Return Format: JSON
Request Parameters: None
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"sorts": [
{
"lognum": "0",
"sortname": "Sports",
"description": "",
"alias": "sport",
"sid": 1,
"taxis": 0,
"pid": 0,
"template": "",
"children": [
{
"lognum": "0",
"sortname": "Football",
"description": "",
"alias": "football",
"sid": 2,
"taxis": 0,
"pid": 1,
"template": ""
}
]
}
]
}
}
Note Post
- Note Post Interface
- Interface URL: https://yourdomain/?rest-api=note_post
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: [API Key Authentication] or [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| t | Yes | Note Content |
| private | No | Whether private, y private, n public, default public |
| author_uid | No | Author User ID, can be viewed in the backend user management page |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"note_id": 4
}
}
Note List
- Get Note List Interface
- Interface URL: https://yourdomain/?rest-api=note_list
- Request Method: GET
- Interface Authentication Method: [API Key Authentication] or [Cookie Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| page | No | Page number, default starts from 1 |
| count | No | Number of notes per page, default follows backend settings |
| author_uid | No | Author User ID, can be viewed in the backend user management page |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"notes": [
{
"t": "<h1>test note</h1>",
"t_raw": "# test note",
"date": "47 seconds ago",
"author_id": 1,
"author_name": "emer"
},
...
,
]
}
}
Resource File Upload
- Upload images, zip packages and other resource files
- Interface URL: https://yourdomain/?rest-api=upload
- Request Method: POST
- Request Body Format: Form Data (application/x-www-form-urlencoded)
- Interface Authentication Method: [API Key Authentication]
- Return Format: JSON
Request Parameters
| Parameter | Required | Description |
|---|---|---|
| file | Yes | File, media file to upload (binary file) |
| author_uid | No | Author User ID, can be viewed in the backend user management page |
| sid | No | Resource Category ID |
Return Result
{
"code": 0,
"msg": "ok",
"data": {
"media_id": 80,
"url": "http://yourdomain/content/uploadfile/202307/7e6f1690266418.png",
"file_info": {
"file_name": "icon-1024.png",
"mime_type": "image/png",
"size": 258642,
"width": 1024,
"height": 1024,
"file_path": "../content/uploadfile/202307/7e6f1690266418.png",
"thum_file": "../content/uploadfile/202307/thum-7e6f1690266418.png"
}
}
}
Common Error Messages
- Error Return Format: json
| Error Message | Description | HTTP Status Code |
|---|---|---|
| sign error | Signature Error | 401 |
| api is closed | API not enabled, please enable in backend settings | 400 |
| API function is not exist | Non-existent API method | 400 |
| parameter error | Required parameter missing | 400 |
Error Return Example
{
"code": 1,
"msg": "sign error",
"data": ""
}
Call Examples
PHP Call Example
PHP Call Example (Post Note)
<?php
// API Key, found in System - Settings - API Settings
$apikey = 'your_api_key';
// Request Parameters
$data = array(
't' => 'This is a test note',
'author_uid' => '1',
'api_key' => $apikey
);
// Request URL
$url = 'https://yourdomain/?rest-api=note_post';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));// Set request parameters
curl_setopt($ch, CURLOPT_URL, $url);// Set request URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// Set return result not to output directly
$response = curl_exec($ch);// Execute request and get response data
curl_close($ch);// Close curl
echo $response; // Output response result
python Call Example
python Call Example (Post Note)
import time
import hashlib
import requests
# API Key, found in System - Settings - API Settings
apikey = 'your_api_key'
# Request Parameters
data = {
't': 'This is a test note',
'author_uid': '1',
'api_key': apikey
}
# Request URL
url = 'https://yourdomain/?rest-api=note_post'
response = requests.post(url, data=data)
print(response.text) # Output response result
js Call Example
js Call Example (Post Comment)
// Used jquery
// Get form data
const gid = $('#gid').val();
const comname = $('#comname').val();
const comment = $('#comment').val();
const commail = $('#commail').val();
const comurl = $('#comurl').val();
const imgcode = $('#imgcode').val();
const pid = $('#pid').val();
const resp = $('#resp').val();
// Send POST request
$.post('https://yourdomain/index.php?action=addcom', {
gid: gid,
comname: comname,
comment: comment,
commail: commail,
comurl: comurl,
imgcode: imgcode,
pid: pid,
resp: resp
}).done(function (response) {
if (response.code === 0) {
alert('Comment successful!');
// Refresh page or other operations
} else {
alert(response.msg);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log('Request failed: ' + textStatus);
});
File Upload Example
PHP Implementation of Image Upload Example
<?php
// API Key, found in System - Settings - API Settings
$apikey = 'your_api_key';
// Request URL
$url = 'https://yourdomain/?rest-api=upload';
// File path to upload
$file_path = '/path/to/your/file.png';
// Construct POST data
$post_data = array(
'file' => new CURLFile($file_path),
'sid' => 1, // Resource Category ID, omit if not needed
'api_key' => $apikey
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);// Set request URL
curl_setopt($ch, CURLOPT_POST, 1);// Set as POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);// Set POST data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// Set return result not to output directly
$response = curl_exec($ch);// Execute request and get response data
// Check if error occurred
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
// Parse JSON response data
$json_response = json_decode($response, true);
if ($json_response['code'] === 0) {
echo 'Upload successful! Media ID: ' . $json_response['data']['media_id'];
echo 'File URL: ' . $json_response['data']['url'];
} else {
echo 'Upload failed: ' . $json_response['msg'];
}
}
curl_close($ch);// Close curl