Skip to main content

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

tip

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:
ParameterRequiredDescription
req_signYesInterface signature, see the calculation signature rules below
req_timeYesUnix 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:
ParameterRequiredDescription
api_keyYesAPI key, found in System - Settings - API Settings page

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

Request Parameters

ParameterRequiredDescription
userYesUsername, Email
pwYesPassword
persistNoRemember me, keep login status (value: 1)
login_codeNoImage verification code
respYesPass string "json"
{
"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

ParameterRequiredDescription
mailYesEmail
passwdYesPassword
repasswdYesRepeat Password
login_codeNoImage verification code
mail_codeNoEmail verification code
respYesPass 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

ParameterRequiredDescription
mailYesEmail
login_codeNoImage verification code
respYesPass 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

ParameterRequiredDescription
mail_codeYesEmail verification code
passwdYesPassword
repasswdYesRepeat Password
respYesPass 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

Request Parameters

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

Request Parameters

ParameterRequiredDescription
tokenYesBackend token, get method: LoginAuth::genToken()
nameNoNickname
descriptionNoPersonal Description
usernameNoLogin Username

Return Result

{
"code": 0,
"msg": "ok",
"data": ""
}

Change Password

Request Parameters

ParameterRequiredDescription
tokenYesToken, get method: LoginAuth::genToken()
new_passwdNoNew Password
new_passwd2NoRepeat New Password

Return Result

{
"code": 0,
"msg": "ok",
"data": ""
}

Upload Avatar

Request Parameters

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

ParameterRequiredDescription
gidYesArticle ID
comnameYesCommenter Name
commentYesComment Content
commailNoCommenter Email
comurlNoCommenter Homepage URL
avatarNoCommenter Avatar Image URL
imgcodeNoImage Verification Code
pidNoReplied Comment ID
respYesPass 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

ParameterRequiredDescription
cidYesComment ID

Return Result

{
"code": 0,
"msg": "ok",
"data": ""
}

Comment List

Request Parameters

ParameterRequiredDescription
idYesArticle ID
pageNoComment 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

Request Parameters

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

ParameterRequiredDescription
gidYesArticle ID
nameNoLiker Name
avatarNoLiker 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

ParameterRequiredDescription
gidYesArticle ID

Return Result

{
"code": 0,
"msg": "ok",
"data": {}
}

Like List

Request Parameters

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

ParameterRequiredDescription
titleYesTitle
contentYesContent
excerptNoExcerpt
coverNoCover
author_uidNoAuthor User ID, can be viewed in the backend user management page
sort_idNoCategory ID, can be viewed in the backend category management page
tagsNoTags, multiple separated by half-width commas, e.g.: PHP,MySQL
draftNoWhether to publish as a draft, yes y, no n (default n)
post_dateNoPublish time, e.g.: 2022-05-03 23:30:16
topNoSticky on homepage, yes y, no n, default n
sortopNoSticky in category, yes y, no n, default n
allow_remarkNoAllow comments, yes y, no n, default n
passwordNoAccess Password
linkNoRedirect link, if filled, it will jump directly to this address without displaying article content
field_keys[]NoCustom field name, e.g. price: price
field_values[]NoCustom field value, e.g. price value: 9.9
auto_coverNoAutomatically 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

ParameterRequiredDescription
idYesArticle (Draft) ID
titleYesTitle
contentNoContent
excerptNoExcerpt
coverNoCover
author_uidNoAuthor User ID, can be viewed in the backend user management page
sort_idNoCategory ID, can be viewed in the backend category management page
tagsNoTags, multiple separated by half-width commas, e.g.: PHP,MySQL
draftNoWhether to publish as a draft, yes y, no n (default n)
post_dateNoPublish 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

ParameterRequiredDescription
pageNoPage number, default starts from 1
countNoNumber of articles per page, default follows backend settings
sort_idNoArticle Category ID, can be viewed in the backend category management page
keywordNoSearch keyword, only matches article title
tagNoArticle Tag
orderNoArticle 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

Request Parameters

ParameterRequiredDescription
idYesArticle ID
passwordNoArticle 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

ParameterDescription
idArticle ID
titleArticle Title
coverArticle Cover Image
urlArticle URL
descriptionArticle List Excerpt
description_rawArticle List Excerpt (markdown original)
contentArticle Detail Content
content_rawArticle Detail Content (markdown original)
excerptArticle Detail Excerpt
excerpt_rawArticle Detail Excerpt (markdown original)
datePublish Date
author_idAuthor ID
author_nameAuthor Nickname
author_avatarAuthor Avatar
sort_idCategory ID
sort_nameCategory Name
viewsRead Count
comnumComment Count
like_countLike Count
topSticky on Homepage y yes n no
sortopSticky in Category y yes n no
tagsTags
need_pwdPassword Protected y yes n no
fieldsCustom 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

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

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

ParameterRequiredDescription
tYesNote Content
privateNoWhether private, y private, n public, default public
author_uidNoAuthor 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

ParameterRequiredDescription
pageNoPage number, default starts from 1
countNoNumber of notes per page, default follows backend settings
author_uidNoAuthor 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

ParameterRequiredDescription
fileYesFile, media file to upload (binary file)
author_uidNoAuthor User ID, can be viewed in the backend user management page
sidNoResource 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 MessageDescriptionHTTP Status Code
sign errorSignature Error401
api is closedAPI not enabled, please enable in backend settings400
API function is not existNon-existent API method400
parameter errorRequired parameter missing400

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