codebin

CodeBin API 接口文档

CodeBin API Documentation

开放 API 接口,支持代码片段的创建、查询与管理,来自 codebin.net

Open API for code snippets creation, querying and management, powered by codebin.net

GET 最近代码片段Recent Pastes

https://codebin.net/api/pastes
接口说明
Recent Pastes API
成功响应示例:
Possible Good API Responses: (example)
{
    "current_page": 1,
    "data": [
        {
            "title": "User paste",
            "syntax": "none",
            "slug": "U2m07ANokE",
            "created_at": "2019-11-26 18:12:41",
            "password": null,
            "expire_time": null,
            "views": 3,
            "password_protected": false,
            "url": "https://codebin.net/U2m07ANokE"
        }
    ],
    "first_page_url": "https://codebin.net/api/search?page=1",
    "from": 1,
    "next_page_url": null,
    "path": "https://codebin.net/api/search",
    "per_page": "50",
    "prev_page_url": null,
    "to": 1
}
请求头
Headers
Accept:
application/json
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/pastes' \
--header 'Accept: application/json'

GET 语法归档列表Archive List

Endpoint: https://codebin.net/api/archive
接口说明
Archive List
成功响应示例:
Possible Good API Responses: (example)
[
    {
        "name": ".properties",
        "slug": "properties",
        "url": "https://codebin.net/archive/properties"
    },
    {
        "name": "6502 Assembly",
        "slug": "asm6502",
        "url": "https://codebin.net/archive/asm6502"
    },
    {
        "name": "ABAP",
        "slug": "abap",
        "url": "https://codebin.net/archive/abap"
    }
]
失败响应:
Possible Bad API Responses:
{
    "error": "This feature is disabled"
}
请求头
Headers
Accept:
application/json
请求示例
Example Request
curl --location 'https://codebin.net/api/archive' \
--header 'Accept: application/json'

GET 语法归档内容Archive

Endpoint: https://codebin.net/api/archive/none
请求路径说明:
Include Archive Syntax Slug when you request the url:
https://codebin.net/api/archive/{slug}
成功响应示例:
Possible Good API Responses: (example)
{
    "current_page": 1,
    "data": [
        {
            "title": "User paste",
            "syntax": "none",
            "slug": "U2m07ANokE",
            "created_at": "2019-11-26 18:12:41",
            "password": null,
            "expire_time": null,
            "views": 3,
            "password_protected": false,
            "url": "https://codebin.net/U2m07ANokE"
        }
    ],
    "first_page_url": "https://codebin.net/api/search?page=1",
    "from": 1,
    "next_page_url": null,
    "path": "https://codebin.net/api/search",
    "per_page": "50",
    "prev_page_url": null,
    "to": 1
}
失败响应:
Possible Bad API Responses:
{
    "error": "This feature is disabled"
}
请求头
Headers
Accept:
application/json
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/archive/none' \
--header 'Accept: application/json'

POST 用户登录Login

Endpoint: https://codebin.net/api/login
请求参数说明:
Include all the following POST parameters when you request the url:
  1. username - 登录用户名
  2. password - 登录密码
  3. username - this will be username of the account you want to login
  4. password - this will be password of the account you want to login
成功响应示例:
Possible Good API Responses: (example)
{
    "success": {
        "message": "You successfully logged in",
        "api_token": "6729ac220899f8a541f9b4570024fc24923406a3efea9106b44033deaa27a23d",
        "user": {
            "name": "admin",
            "email": "admin@example.com",
            "avatar": "https://ui-avatars.com/api/?size=80&background=random&name=admin",
            "about": null,
            "default_paste": {
                "title": "My Awesome Paste",
                "status": "1",
                "syntax": "markup",
                "expire": "N",
                "password": null,
                "encrypted": 1
            },
            "gp": null,
            "fb": null,
            "tw": null
        }
    }
}
失败响应:
Possible Bad API Responses:
{
    "error": "Your account is banned"
}

{
    "error": "Invalid username or password"
}
请求头
Headers
Accept:
application/json
请求体 (formdata)
Body (formdata)
username:
admin
登录用户名
this will be username of the account you want to login
password:
admin123
登录密码
this will be password of the account you want to login
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/login' \
--header 'Accept: application/json' \
--form 'username="admin"' \
--form 'password="admin123"'

POST 用户登出Logout

Endpoint: https://codebin.net/api/logout
身份认证说明
Include the auth token in Authorization header of the user you want to logout
Bearer {token}
成功响应:
Possible Good API Responses:
{
    "success": "You successfully logged out"
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}
请求头
Headers
Authorization:
Bearer 9bc9f4281910841091cbdea4c8bbe9dde817ffc0b8df897a50dc56cc24325a98
Bearer {token} - 用户登录令牌
Bearer {token} - token is the session key of the logged in user
Accept:
application/json
请求示例
Example Request
curl --location --request POST 'https://codebin.net/api/logout' \
--header 'Authorization: Bearer 9bc9f4281910841091cbdea4c8bbe9dde817ffc0b8df897a50dc56cc24325a98' \
--header 'Accept:  application/json'

POST 获取代码片段Get Paste

Endpoint: https://codebin.net/api/pastes/Ow4auxc8HM
请求参数说明:
Include all the following POST parameters when you request the url:
  1. password - 您想请求粘贴的访问密码(非加密粘贴可省略)
  2. password - password of the paste you want requesting (Optional if paste is not password protected)
成功响应:
Possible Good API Responses:
{
    "success": {
        "title": "User paste",
        "slug": "U2m07ANokE",
        "syntax": "U2m07ANokE",
        "expire_time": null,
        "status": 1,
        "views": 3,
        "description": "Hello thiaosd as dasda s",
        "encrypted": 0,
        "extension": "txt",
        "created_at": "2019-11-26 18:12:41",
        "url": "https://codebin.net/U2m07ANokE",
        "content": "Hello thiaosd as dasda s",
        "user": {
            "name": "admin",
            "avatar": "https://ui-avatars.com/api/?size=80&background=random&name=admin",
            "url": "https://codebin.net/u/admin"
        }
    }
}
失败响应:
Possible Bad API Responses:
{
    "error": "Paste not found"
}

{
    "error": "You are not allowed to access this paste"
}

{
    "error": "You are not allowed to access private paste"
}

{
    "error": "Paste is expired"
}

{
    "error": "Invalid password"
}
请求头
Headers
Accept:
application/json
请求体 (formdata)
Body (formdata)
password:
1234
访问密码(非加密片段可省略)
password of the paste you want requesting (Optional if paste is not password protected)
请求示例
Example Request
curl --location 'https://codebin.net/api/pastes/Ow4auxc8HM' \
--header 'Accept: application/json' \
--form 'password="1234"'

POST 创建代码片段Paste Create

Endpoint: https://codebin.net/api/paste/create
请求参数说明:
Include all the following POST parameters when you request the url:
  1. content => 必填参数,最少 1 个字符
  2. status => 必填参数,用于设置代码片段公开类型;公开 = 0、仅链接可见 = 1、私密 = 2; (仅链接可见说明:非公开、不列表,只有拿到链接才能访问)
  3. syntax => 选填参数,值必须为归档列表接口返回的合法语法别名
  4. expire => 选填参数,用于设置代码片段过期时间,可选值如下:永不失效 - N、10 分钟 - 10M、1 小时 - 1H、1 天 - 1D、1 周 - 1W、2 周 - 2W、1 个月 - 1M、6 个月 - 6M、1 年 - 1Y、阅后即焚 - SD
  5. title => 选填参数,用于设置代码片段标题,字符串最大长度 80
  6. password => 选填参数,用于设置访问密码,最大长度 50
  7. content => this is required parameter with minimum 1 length
  8. status => this is required parameter which makes paste public, unlisted or private, public = 0, unlisted = 1, private = 2
  9. syntax => this is optional parameter, value must be valid syntax slug from given Archive List API
  10. expire => this is optional parameter which makes is used to set expire time of paste, following are the values, Never - N, 10 Minutes- 10M, 1 Hour - 1H, 1 Day - 1D, 1 Week - 1W, 2 Week - 2W, 1 Month - 1M, 6 Month - 6M, 1 Year - 1Y, Self Destoy - SD
  11. title => this is optional parameter which sets paste title, value can be string with max length upto 80
  12. password => this is optional parameter which makes paste password protected, value can have max length upto 50
成功响应:
Possible Good API Responses:
{
    "success": {
        "messages": "Paste successfully created",
        "slug": "YvS0bRhQLK",
        "paste_url": "https://codebin.net/YvS0bRhQLK"
    }
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}

{
    "error": {
        "content": [
            "The Content field is required."
        ],
        "status": [
            "The Status field is required."
        ]
    }
}

{
    "error": "User pasting is currently disabled"
}

{
    "error": "Public pasting is currently disabled please login to create a paste"
}

{
    "error": "Max allowed content size is N kb"
}

{
    "error": "Daily paste limit reached"
}

{
    "error": "Please wait N minutes before making another paste"
}

{
    "error": "Daily paste limit reached, Please login to increase your paste limit"
}
请求头
Headers
Accept:
application/json
Authorization:
Bearer 797a51c84a75ea799ad02b0977e31a3147d2325573add6440845d33387944cfb
Bearer {token} - 用户登录令牌
Bearer {token} - session key of the logged in user
请求体 (formdata)
Body (formdata)
content:
this is new paste
必填 - 代码片段内容
Required - Content of your paste
status:
1
Required - public = 0, unlisted = 1, private = 2
expire:
N
Optional - Never - N,10 Minutes- 10M, 1 Hour - 1H, 1 Day - 1D, 1 Week - 1W, 2 Week - 2W, 1 Month - 1M, 6 Month - 6M, 1 Year - 1Y, Self Destoy - SD
title:
My Paste
Optional - String, Max length 80
syntax:
none
Optional - Valid syntax slug from given Archive List API
password:
12345
Optional - String, Max length 50
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/paste/create' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer 797a51c84a75ea799ad02b0977e31a3147d2325573add6440845d33387944cfb' \
--form 'content="this is new paste"' \
--form 'status="1"' \
--form 'expire="N"' \
--form 'title="My Paste"' \
--form 'syntax="none"' \
--form 'password="12345"'

POST 更新代码片段Paste Update

Endpoint: https://codebin.net/api/paste/update
请求参数说明:
Include all the following POST parameters when you request the url:
  1. slug - 必填,需传入要编辑代码片段的唯一标识别名
  2. content - 必填,内容最小长度为1
  3. status - 可选,设置代码片段公开类型;公开=0、仅链接可见=1、私密=2(仅链接可见说明:非公开、不列表,只有拿到链接才能访问)
  4. syntax - 可选,须为归档列表接口提供的合法语法别名
  5. title - 可选,设置代码片段标题,最大支持80个字符
  6. password - 可选,设置代码片段访问密码,最大支持50个字符
  7. slug - this is required parameter which must be slug of your paste you want to edit
  8. content - this is required parameter with minimum 1 length
  9. status - this is optional parameter which makes paste public, unlisted or private, public = 0, unlisted = 1, private = 2
  10. syntax - this is optional parameter, value must be valid syntax slug from given Archive List API
  11. title - this is optional parameter which sets paste title, value can be string with max length upto 80
  12. password - this is optional parameter which makes paste password protected, value can have max length upto 50
成功响应:
Possible Good API Responses:
{
    "success": {
        "messages": "Paste successfully updated",
        "slug": "YvS0bRhQLK",
        "paste_url": "https://codebin.net/YvS0bRhQLK"
    }
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}

{
    "error": "Paste not found"
}

{
    "error": {
        "content": [
            "The Content field is required."
        ]
    }
}

{
    "error": "User pasting is currently disabled"
}

{
    "error": "Public pasting is currently disabled please login to create a paste"
}

{
    "error": "Max allowed content size is N kb"
}

{
    "error": "Daily paste limit reached"
}

{
    "error": "Please wait N minutes before making another paste"
}

{
    "error": "Daily paste limit reached, Please login to increase your paste limit"
}
请求头
Headers
Accept:
application/json
Authorization:
Bearer 34b7d4d8d2c879b4539178c3215fbff87822ad0d8aafa122293219532fc8dfe9
Bearer {token} - 用户登录令牌
Bearer {token} - session key of logged user
请求体 (formdata)
Body (formdata)
slug:
ZvV4XBhAaK
必填 - 片段唯一标识
Required - Slug of your paste to edit
content:

this is new paste

必填 - 代码片段内容
Required - Content of your paste
title:
My Paste
Optional - String, Max length 80
syntax:
none
Optional - Valid syntax slug from given Archive List API
password:
12345
Optional - String, Max length 50
status:
1
Optional - public = 0, unlisted = 1, private = 2
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/paste/update' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer 34b7d4d8d2c879b4539178c3215fbff87822ad0d8aafa122293219532fc8dfe9' \
--form 'slug="ZvV4XBhAaK"' \
--form 'content="<p>this is new paste</p>"' \
--form 'title="My Paste"' \
--form 'syntax="none"' \
--form 'password="12345"' \
--form 'status="1"'

POST 删除代码片段Paste Delete

Endpoint: https://codebin.net/api/paste/delete
请求参数说明:
Include all the following POST parameters when you request the url:
  1. slug - 必填,片段唯一标识
  2. slug - required, your paste slug to delete
成功响应:
Possible Good API Responses:
{
    "success": "Paste successfully deleted"
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}

{
    "error": "Paste not found"
}
请求头
Headers
Accept:
application/json
Authorization:
Bearer 34b7d4d8d2c879b4539178c3215fbff87822ad0d8aafa122293219532fc8dfe9
Bearer {token} - 用户登录令牌
Bearer {token} - session key of logged user
请求体 (formdata)
Body (formdata)
slug:
ZvV4XBhAaK
必填 - 片段唯一标识
Required - Slug of your paste to delete
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/paste/delete' \
--header 'Authorization: Bearer 34b7d4d8d2c879b4539178c3215fbff87822ad0d8aafa122293219532fc8dfe9' \
--header 'Accept: application/json' \
--form 'slug="ZvV4XBhAaK"'

GET 获取页面内容Get Page

Endpoint: https://codebin.net/api/pages/about
请求路径说明:
Include Page Slug when you request the url:
https://codebin.net/api/pages/{slug}
成功响应示例:
Possible Good API Responses: (example)
{
    "title": "About Us",
    "content": "Lorem ipsum dolor si...",
    "description": " Lorem ipsum dolor si..."
}
失败响应:
Possible Bad API Responses:
{
    "error": "Page not found"
}
请求头
Headers
Accept:
application/json
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/pages/about' \
--header 'Accept: application/json'

GET 用户公开主页User Public Profile & Pastes

Endpoint: https://codebin.net/api/u/admin
请求路径说明:
Include Username when you request the url:
https://codebin.net/api/u/{username}
成功响应示例:
Possible Good API Responses: (example)
{
    "success": {
        "pastes": {
            "current_page": 1,
            "data": [
                {
                    "title": "Hello world",
                    "syntax": "none",
                    "slug": "mgHZkPMqJu",
                    "created_at": "2019-11-26 18:01:53",
                    "password": null,
                    "expire_time": null,
                    "views": 1,
                    "password_protected": false,
                    "url": "https://codebin.net/mgHZkPMqJu"
                }
            ],
            "first_page_url": "https://codebin.net/api/u/admin?page=1",
            "from": 1,
            "next_page_url": null,
            "path": "https://codebin.net/api/u/admin",
            "per_page": 20,
            "prev_page_url": null,
            "to": 1
        },
        "user": {
            "name": "admin",
            "status": null,
            "avatar": "https://ui-avatars.com/api/?size=80&background=random&name=admin",
            "about": null,
            "gp": null,
            "fb": null,
            "tw": null
        }
    }
}
失败响应:
Possible Bad API Responses:
{
    "error": "User not found"
}
请求头
Headers
Accept:
application/json
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/u/admin' \
--header 'Accept: application/json'

GET 我的代码片段Get My Pastes

Endpoint: https://codebin.net/api/my-pastes
接口说明
Get pastes of authorized user
成功响应:
Possible Good API Responses:
{
    "current_page": 1,
    "data": [
        {
            "id": 15,
            "title": null,
            "slug": "BvIJ2Rl8Yr",
            "user_id": 1,
            "ip_address": "::1",
            "content": "this is new paste",
            "syntax": "none",
            "expire_time": null,
            "status": 1,
            "views": 0,
            "password": null,
            "encrypted": 0,
            "self_destroy": null,
            "storage": 1,
            "created_at": "2019-11-29 21:54:05",
            "updated_at": "2019-11-29 21:54:05",
            "password_protected": false,
            "url": "https://codebin.net/BvIJ2Rl8Yr"
        }
    ],
    "first_page_url": "https://codebin.net/api/my-pastes?page=1",
    "from": 1,
    "next_page_url": null,
    "path": "https://codebin.net/api/my-pastes",
    "per_page": "50",
    "prev_page_url": null,
    "to": 4
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}
请求头
Headers
Authorization:
Bearer 56d21e3066b7828419016c5b90e18b6e55f4f6d8ea57d85dedda60dfd0f4d581
Bearer {token} - 用户登录令牌
Bearer {token} - session key of logged user
Accept:
application/json
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/my-pastes' \
--header 'Authorization: Bearer 56d21e3066b7828419016c5b90e18b6e55f4f6d8ea57d85dedda60dfd0f4d581' \
--header 'Accept: application/json'

POST 举报违规内容Report Paste Issue

Endpoint: https://codebin.net/api/report-issue
成功响应:
Possible Good API Responses:
{
    "success": "Paste successfully reported"
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}

{
    "error": "This feature is disabled"
}
请求头
Headers
Authorization:
Bearer 256fae02f45ccdd6671e031e9843367ee426e2ea68ba4ac5cf0c9d1b79350c87
Bearer {token} - 用户登录令牌
Bearer {token} - session key of logged user
Accept:
application/json
请求体 (formdata)
Body (formdata)
slug:
U2m07ANokE
必填 - 片段唯一标识
Required - Paste slug to report
reason:
I do not like this paste
必填 - 举报原因,10-1000字符
Required - Reason, 10-1000 chars
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/report-issue' \
--header 'Authorization: Bearer 256fae02f45ccdd6671e031e9843367ee426e2ea68ba4ac5cf0c9d1b79350c87' \
--header 'Accept: application/json' \
--form 'slug="U2m07ANokE"' \
--form 'reason="I do not like this paste"'

GET 获取当前用户信息Get User

获取认证用户资料
Get authorized user profile
成功响应:
Possible Good API Responses:
{
    "success": {
        "name": "admin",
        "status": null,
        "avatar": "https://ui-avatars.com/api/?size=80&background=random&name=admin",
        "about": null,
        "default_paste": {
            "title": "My Awesome Paste",
            "status": "1",
            "syntax": "markup",
            "expire": "N",
            "password": null,
            "encrypted": 1
        },
        "gp": null,
        "fb": null,
        "tw": null
    }
}
失败响应:
Possible Bad API Responses:
{
    "message": "Unauthenticated."
}

{
    "error": "User not found"
}
请求头
Headers
Authorization:
Bearer 797a51c84a75ea799ad02b0977e31a3147d2325573add6440845d33387944cfb
Bearer {token} - 用户登录令牌
Bearer {token} - session key of logged user
Accept:
application/json
请求示例 - curl
Example Request - curl
curl --location 'https://codebin.net/api/profile' \
--header 'Authorization: Bearer 797a51c84a75ea799ad02b0977e31a3147d2325573add6440845d33387944cfb' \
--header 'Accept: application/json'
Copied!