API 文档

API地址: https://2index.ninja/api/v1/

要向 API 发出请求,您需要在 Authorization 标头中传递 Bearer 访问令牌。

 curl https://2index.ninja/api/v1/account -H "Authorization: Bearer API_TOKEN"

访问令牌可以在用户账户的相应部分获取。

每个请求的响应都包含success参数,该参数决定请求是否成功。errors 参数包含errors消息。

在某些情况下,如果返回403错误,则需要指定user-agent,例如:

 curl https://2index.ninja/api/v1/account -H "Authorization: Bearer API_TOKEN" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

请求可能会受到托管的限制,在这种情况下我们建议使用代理。

使用帐户的方法

获取帐户详细信息

您需要向account地址执行 GET 请求

GET https://2index.ninja/api/v1/account

响应将是 JSON 格式的数据:

 {
    "success": true,
    "account": {
        "email": "[email protected]",
        "tariff": "White Ninja",
        "balance": 100.0,
        "available_projects": 1,
        "available_links": 100,
        "available_indexation_check_links": 500,
        "link_sending_speed": 100,
        "tariff_available": true,
        "tariff_expiring_date": "2025-01-16T14:26:11.000000Z",
        "email_verified": false,
        "link_cost": "$0.00056"
    }
}

处理项目的方法

获取项目列表

您需要向project地址执行 GET 请求

GET https://2index.ninja/api/v1/project

响应将是 JSON 格式的数据:

 {
    "success": true,
    "projects": [
        {
            "id": 1,
            "name": "Project name",
            "type": "indexing",
            "website": "https://domain.com/",
            "status": "in progress",
            "created_at": "2024-03-01 14:34:56",
            "links_type": "internal",
            "google_account_access_granted": 0,
            "links_total": 500,
            "links_sending_speed": 400,
            "links_sent_google": 100,
            "links_sent_yandex": 40,
            "links_sent_bing": 100,
            "in_queue": 360,
            "sent_links": 100,
            "indexed": 30,
            "not_indexed": 0,
            "download_queue_url": "DOWNLOAD_QUEUE_URL",
            "download_sent_url": "DOWNLOAD_SENT_URL",
            "download_indexed_url": "DOWNLOAD_INDEXED_URL",
            "download_unindexed_url": "DOWNLOAD_UNINDEXED_URL"
        },
        {
            "id": "2",
            "name": "Project 2 name",
            "type": "indexing_check",
            "status": "in progress",
            "created_at": "2024-03-01 14:34:56",
            "links_total": 200,
            "links_checking_speed": 100,
            "in_queue": 100,
            "checked": 100,
            "indexed": 70,
            "not_indexed": 30,
            "download_queue_url": "DOWNLOAD_QUEUE_URL",
            "download_indexed_url": "DOWNLOAD_INDEXED_URL",
            "download_unindexed_url": "DOWNLOAD_UNINDEXED_URL",
            "download_all_url": "DOWNLOAD_ALL_URL",
            "download_checked_url": "DOWNLOAD_CHECKED_URL",
        }
        ...
    ]
}

获取项目数据

您需要向地址project/{project_id}执行 GET 请求

GET https://2index.ninja/api/v1/project/1

响应将是 JSON 格式的数据:

  • 对于索引项目:
 {
    "success": true,
    "project": {
        "id": 1,
        "name": "Project name",
        "type": "indexing",
        "website": "https://domain.com/",
        "status": "in progress",
        "created_at": "2024-03-01 14:34:56",
        "links_type": "internal",
        "google_account_access_granted": 0,
        "links_total": 500,
        "links_sending_speed": 400,
        "links_sent_google": 100,
        "links_sent_yandex": 40,
        "links_sent_bing": 100,
        "in_queue": 360,
        "sent_links": 100,
        "indexed": 30,
        "not_indexed": 0,
        "download_queue_url": "DOWNLOAD_QUEUE_URL",
        "download_sent_url": "DOWNLOAD_SENT_URL",
        "download_indexed_url": "DOWNLOAD_INDEXED_URL",
        "download_unindexed_url": "DOWNLOAD_UNINDEXED_URL"
    }
}
  • 对于索引验证项目:
 {
    "success": true,
    "project": {
        "id": "2",
        "name": "Project 2 name",
        "type": "indexing_check",
        "status": "in progress",
        "created_at": "2024-03-01 14:34:56",
        "links_total": 200,
        "links_checking_speed": 100,
        "in_queue": 100,
        "checked": 100,
        "indexed": 70,
        "not_indexed": 30,
        "download_queue_url": "DOWNLOAD_QUEUE_URL",
        "download_indexed_url": "DOWNLOAD_INDEXED_URL",
        "download_unindexed_url": "DOWNLOAD_UNINDEXED_URL",
        "download_all_url": "DOWNLOAD_ALL_URL",
        "download_checked_url": "DOWNLOAD_CHECKED_URL"
    }
}

创建项目

您需要向project地址发出POST请求

POST https://2index.ninja/api/v1/project

请求参数:

场地 类型 一定 描述
姓名 细绳 是的 项目名称
网站 细绳 是的* 网站地址格式为https://site.domain/
*如果项目类型为indexing ,则为必填项
外部链接 布尔值 项目对外链接。如无特别说明,则仅限国内使用。
索引速度 整数 不** 项目索引速度,若未指定,则将应用账户中所有可用的速度。用于indexing类型的项目。对于indexing_check类型的项目,则使用checking_speed
检查速度 整数 不** 项目链接检查速度,如未指定,将应用账户所有可用速度。用于indexing_check类型的项目。对于indexing类型的项目,使用indexing_speed
类型 细绳 项目类型。
可能的选项: indexing - 索引链接, indexing_check - 检查索引链接。
如果没有指定,则会创建链接索引项目indexing

** 创建任何类型的项目时,您可以使用indexing_speedchecking_speed参数,它们互为别名,但如果同时传递两者,则将使用indexing_speed

响应将是 JSON 格式的数据:

 {
    "success": true,
    "message": "The project has been successfully created" 
}

创建链接索引项目的示例: POST https://2index.ninja/api/v1/project

 name: Project 1 website: https://website.com for_external_links: 1 indexing_speed: 100

创建项目以检查链接索引的示例: POST https://2index.ninja/api/v1/project

 name: Project 2 checking_speed: 100

清除索引队列

您需要向project/{project_id}/clear_queue发出 POST 请求

POST https://2index.ninja/api/v1/project/1/clear_queue

响应将是 JSON 格式的数据:

 {
    "success": true,
    "message": "The indexing queue has been cleared successfully. X links have been removed" 
}

或者返回相应的错误信息:

 {
    "success": false,
    "errors": ["Project not found"] 
}

使用链接的方法

添加链接

您需要发出 POST 请求来link/add

 POST https://2index.ninja/api/v1/link/add

请求参数:

场地 一定 描述
项目 ID 是的 项目 ID
链接 是的 链接列表。可以作为链接数组或文本传递(每个链接占一行)
谷歌 不,只要 Yandex 或 Bing 向 Google 提交链接
雅德克斯 不,只要有谷歌或必应 将链接发送到 Yandex
必应 不,只要有 google 或 yandex 向 Bing 提交链接
google_access_granted 已授予 Google 帐户访问权限

响应将是 JSON 格式的数据:

 {
    "success": true,
    "message": "Links have been successfully added to the project" 
}

如果列表中存在错误的链接,则不会添加链接,并且会收到相应的错误消息:

 {
    "success": false,
    "errors": ["You sent invalid links"],
    "invalid_links": ["http://wrong.link"] 
}

对于索引验证项目,链接的添加方式与索引相同, google_access_granted参数并非必须传递,将被忽略。必须指定搜索引擎,但目前仅在 Google 中提供验证。

按项目名称添加链接

您需要向link/add_simple发出POST请求。如果指定名称的项目不存在,则会以最快的发送速度自动创建。

 POST https://2index.ninja/api/v1/link/add_simple

请求参数:

场地 一定 描述
项目名称 项目名称。如果未指定,则将创建名为"default"的项目。
链接 是的 链接列表。可以作为数组或文本传递(每个链接占一行)。
谷歌 否,如果指定了 yandex 或 bing 向 Google 提交链接。
雅德克斯 否,如果指定了 google 或 bing 将链接发送至 Yandex。
必应 否,如果指定了 google 或 yandex 向 Bing 提交链接。
google_access_granted 您的 Google 帐户的访问权限已被授予。

对于索引验证项目,链接的添加方式与索引相同, google_access_granted参数并非必须传递,将被忽略。必须指定搜索引擎,但目前仅在 Google 中提供验证。

示例请求:

 {
    "project_name": "My Website",
    "links": ["https://example.com/page1", "https://example.com/page2"],
    "google": true,
    "yandex": false,
    "bing": true,
    "google_access_granted": false
}

成功响应:

 {
    "success": true,
    "message": "Links have been successfully added to the project",
    "project_name": "My Website",
    "project_id": 12345
}

可能的错误:

  • 如果列表中有任何错误链接:
 {
    "success": false,
    "errors": ["You sent invalid links"],
    "invalid_links": ["http://wrong.link"] 
}
  • 如果创建项目时出现错误:
 {
    "success": false,
    "errors": ["Failed to create the project"] 
}

发送 POST 请求到 /api/v1/link/status

POST https://2index.ninja/api/v1/link/status

请求参数:

字段 必填 说明
project_id 项目 ID
link 要检查的链接
  • 请求成功时,将返回一个 JSON 对象:
{
    "success": true,
    "link": {
        "id": 34368960,
        "url": "https://2index.ninja/",
        "google": "Sent",
        "yandex": "Sent",
        "bing": "Sent",
        "is_external": 1,
        "google_sent": "2025-08-24 20:10:02",
        "yandex_sent": "2025-08-24 20:45:02",
        "bing_sent": "2025-08-24 20:05:05",
        "google_indexed": 1,
        "google_indexing_check_date": "2025-08-29"
    }
}

字段说明:

字段 说明
id 链接 ID
url 链接
google * Google 提交状态
yandex * Yandex 提交状态
bing * Bing 提交状态
is_external 外部链接
google_sent

使用参考源

所有类型的项目均可使用链接源,且处理方式相同。对于索引检查项目,仅可使用 Google。

添加站点地图

/api/v1/sitemap/add发出 POST 请求

POST https://2index.ninja/api/v1/sitemap/add

请求参数:

场地 一定 描述
项目 ID 是的 项目 ID
网站地图 是的 链接到网站地图
谷歌 不,只要 Yandex 或 Bing 向 Google 提交链接
雅德克斯 不,只要有谷歌或必应 将链接发送到 Yandex
必应 不,只要有 google 或 yandex 向 Bing 提交链接
google_access_granted 已授予 Google 帐户访问权限
手表 监控站点地图变化

可能的错误:

错误
数据验证错误。其中一个必填字段缺失或包含无效值。
资费不可用。用户的资费计划已过期。
未找到项目。用户不拥有指定的项目或该项目不存在。
内部服务器错误

答案示例:

站点地图添加成功:

 {
    "success": true,
    "message": "Карта сайта успешно добавлена, мы скачаем её как можно скорее и отправим уведомление по электронной почте после завершения." 
}

验证错误:

 {
    "errors": ["sitemap":["The sitemap field is required."]] 
}

未找到项目:

 {
    "errors": ["Project not found"] 
}

网站地图跟踪状态更新

/api/v1/sitemap/update_watch发出 POST 请求

POST https://2index.ninja/api/v1/sitemap/update_watch

请求参数:

场地 类型 一定 描述
项目 ID 整数 是的 项目 ID
站点地图ID 整数 是的 网站地图编号
手表 布尔值 是的 指示是否监控站点地图的变化

可能的错误:

错误
数据验证错误。其中一个必填字段缺失或包含无效值。
未找到项目或引用源。用户不拥有指定的项目,或者该项目/源不存在。
内部服务器错误

答案示例:

跟踪状态更新成功:

 {
    "success": true 
}

未找到链接源:

 {
    "errors": ["Link source not found"] 
}

删除链接源

/api/v1/sitemap/delete发出 POST 请求

POST https://2index.ninja/api/v1/sitemap/delete

请求参数:

场地 类型 一定 描述
项目 ID 整数 是的 项目 ID
站点地图ID 整数 是的 网站地图编号

可能的错误:

错误
数据验证错误。其中一个必填字段缺失或包含无效值。
未找到项目或引用源。用户不拥有指定的项目,或者该项目/源不存在。
内部服务器错误

答案示例:

成功移除链接源:

 {
    "success": true,
    "message": "Источник ссылок успешно удален" 
}

未找到项目:

 {
     "errors": ["Project not found"] 
}

参考资料列表

要获取已添加的链接源列表,您需要向https://2index.ninja/api/v1/link_sources发出 POST 请求

在请求中传递project_id

返回结果如下:

 [
    {
        "id": 1247,
        "project_id": 3540,
        "name": "urls.txt",
        "type": "text file",
        "created_at": "2025-01-17T15:51:43.000000Z",
        "processing_date": "2025-01-17T15:51:48.000000Z",
        "has_error": false,
        "error_message": "",
        "status": "success",
        "is_pending": false,
        "is_success": true,
        "total_links": 29585,
        "added_links": 29582,
        "invalid_links": 3,
        "watch": 0,
        "google_access_granted": 0,
        "is_external_links": 1,
        "search_engines": {
            "google": "1"
        }
    },
    {
        "id": 22,
        "project_id": 3540,
        "name": "https://2index.ninja/sitemap.xml",
        "type": "sitemap",
        "created_at": "2025-07-03T14:24:23.000000Z",
        "processing_date":,
        "has_error":,
        "error_message":,
        "status": "pending",
        "is_pending": 1,
        "is_success":,
        "total_links": 0,
        "added_links": 0,
        "invalid_links": 0,
        "watch": 1,
        "google_access_granted": 0,
        "is_external_links": 1,
        "search_engines": {
            "google": 1
        }
    }
]

在哪里

id - 链接源的 id
project_id - 项目 ID
name - 附加文件的名称或站点地图的地址
type - 文件源的类型(文本文件或站点地图) - 可以是:
sitemap
text file
created_at - 创建日期
processing_date - 处理日期
has_error - 发生处理错误
error_message - 错误消息
status - 状态 - 可以是:
pending (等待处理),
error (处理错误),
success
is_pending当前正在处理
is_success - 处理成功
total_links - 找到的链接总数
added_links - 添加的链接
invalid_links - 无效链接
watch - 站点地图监控状态
google_access_granted - 是否授予对 Google 帐户的访问权限
is_external_links - 外部链接
search_engines - 连接的搜索引擎

PHP 实现示例

<?php

/**
 * 用于操作2Index.Ninja服务API的类
 */
class API_2IndexNinja
{
    /**
     * API端点URL
     * @var string
     */
    private $url = 'https://2index.ninja/api/v1/';

    /**
     * API访问令牌
     * @var string
     */
    private $access_token;

    /**
     * 类的构造函数。
     *
     * @param string $access_token 用于API授权的访问令牌。
     */
    public function __construct($access_token)
    {
        $this->access_token = $access_token;
    }

    /*
    |--------------------------------------------------------------------------
    | 账户相关方法
    |--------------------------------------------------------------------------
    */

    /**
     * 获取当前账户的信息。
     *
     * @return array|null 来自API的解码响应,包含账户数据。
     */
    public function account()
    {
        return $this->make_request('account');
    }

    /*
    |--------------------------------------------------------------------------
    | 项目相关方法
    |--------------------------------------------------------------------------
    */

    /**
     * 获取所有项目的列表。
     *
     * @return array|null 来自API的解码响应,包含项目列表。
     */
    public function projects_list()
    {
        return $this->make_request('project');
    }

    /**
     * 根据项目ID获取特定项目的数据。
     *
     * @param int $id 项目ID。
     * @return array|null 来自API的解码响应,包含项目数据。
     */
    public function project($id)
    {
        return $this->make_request('project/' . $id);
    }

    /**
     * 添加一个新项目用于链接索引。
     *
     * @param string $name 项目名称。
     * @param string $website 项目网站。
     * @param bool $for_external_links 是否用于外部链接(0或1)。
     * @param int|null $indexing_speed 索引速度。
     * @return array|null 来自API的解码响应,包含已创建项目的数据。
     */
    public function add_project($name, $website, $for_external_links = 0, $indexing_speed = null)
    {
        return $this->make_request('project', [
            'name'               => $name,
            'website'            => $website,
            'for_external_links' => $for_external_links,
            'indexing_speed'     => $indexing_speed,
            'type'               => 'indexing',
        ]);
    }

    /**
     * 添加一个新项目用于检查索引。
     *
     * @param string $name 项目名称。
     * @param int|null $checking_speed 检查速度。
     * @return array|null 来自API的解码响应,包含已创建项目的数据。
     */
    public function add_indexing_check_project($name, $checking_speed = null)
    {
        return $this->make_request('project', [
            'name'           => $name,
            'checking_speed' => $checking_speed,
            'type'           => 'indexing_check',
        ]);
    }

    /**
     * 清除项目的链接队列。
     *
     * @param int $project_id 项目ID。
     * @return array|null 来自API的解码响应。
     */
    public function clear_queue($project_id)
    {
        return $this->make_request('project/' . $project_id . '/clear_queue', true);
    }

    /*
    |--------------------------------------------------------------------------
    | 链接相关方法
    |--------------------------------------------------------------------------
    */

    /**
     * 将链接添加到指定项目。
     *
     * @param int $project_id 项目ID。
     * @param array|string $links 链接数组或单个链接字符串。
     * @param bool $google 是否发送到Google。
     * @param bool $yandex 是否发送到Yandex。
     * @param bool $bing 是否发送到Bing。
     * @param bool $google_access_granted 确认已授予Google访问权限的标志。
     * @return array|null 来自API的解码响应。
     */
    public function add_links($project_id, $links, $google, $yandex, $bing, $google_access_granted = false)
    {
        return $this->make_request('link/add', [
            'project_id'            => $project_id,
            'links'                 => $links,
            'google'                => $google,
            'yandex'                => $yandex,
            'bing'                  => $bing,
            'google_access_granted' => $google_access_granted,
        ]);
    }

    /**
     * 按名称将链接添加到项目。如果项目不存在,将创建新项目。
     *
     * @param array|string $links 链接数组或单个链接字符串。
     * @param bool $google 是否发送到Google。
     * @param bool $yandex 是否发送到Yandex。
     * @param bool $bing 是否发送到Bing。
     * @param string $project_name 项目名称(默认为'default')。
     * @param bool $google_access_granted 确认已授予Google访问权限的标志。
     * @return array|null 来自API的解码响应。
     */
    public function add_links_simple($links, $google, $yandex, $bing, $project_name = 'default', $google_access_granted = false)
    {
        return $this->make_request('link/add_simple', [
            'project_name'          => $project_name,
            'links'                 => $links,
            'google'                => $google,
            'yandex'                => $yandex,
            'bing'                  => $bing,
            'google_access_granted' => $google_access_granted,
        ]);
    }

    /**
     * 获取项目的链接来源。
     *
     * @param int $project_id 项目ID。
     * @return array|null 来自API的解码响应。
     */
    public function link_sources($project_id)
    {
        return $this->make_request('link_sources', [
            'project_id' => $project_id
        ]);
    }

    /**
     * 获取指定链接的状态
     * 如果同一个链接被多次发送,将显示最后一次发送的链接状态
     *
     * @param int $project_id 项目ID
     * @param string $link 检查链接
     * @return array 链接状态
     */
    public function checkLink($project_id, $link)
    {
        return $this->make_request('link/status', [
            'project_id' => $project_id,
            'link' => $link,
        ]);
    }

    /**
     * 获取指定链接的状态
     *
     * @param int $link_id 链接ID
     * @return array 链接状态
     */
    public function checkLinkById($link_id)
    {
        return $this->make_request('link/status/' . $link_id);
    }

    /**
     * 重新提交未编入索引的链接
     *
     * 如果传递了未提交的链接,它们也会被添加到队列中。
     *
     * @param int $project_id 项目 ID
     * @param int $max_attempts 链接重新提交的最大次数(1 到 10)
     * @param array $links(可选)需要重新提交以编入索引的链接数组;如果未传递任何链接,则重新提交项目中所有未编入索引的链接。
     * @return void
     */
    public function resent_notindexed_links($project_id, $max_attempts, array $links = [])
    {
        return $this->make_request('link/resent_notindexed_links/' . $project_id, [
            'max_attempts' => $max_attempts,
            'links' => $links,
        ]);
    }

    /**
     * 从项目中删除链接
     *
     * @param string|array $link
     * @return void
     */
    public function deleteUrls($project_id, $link)
    {
        return $this->make_request('link/delete/' . $project_id, [
            'link' => $link,
        ]);
    }

    /*
    |--------------------------------------------------------------------------
    | 链接来源相关方法
    |--------------------------------------------------------------------------
    */

    /**
     * 将Sitemap添加到项目。
     *
     * @param int $project_id 项目ID。
     * @param string $sitemap_url Sitemap文件URL。
     * @param bool $google 是否发送到Google。
     * @param bool $yandex 是否发送到Yandex。
     * @param bool $bing 是否发送到Bing。
     * @param bool $google_access_granted 确认已授予Google访问权限的标志。
     * @param bool $watch 是否启用Sitemap更改跟踪。
     * @return array|null 来自API的解码响应。
     */
    public function add_sitemap($project_id, $sitemap_url, $google, $yandex, $bing, $google_access_granted = false, $watch = false)
    {
        return $this->make_request('sitemap/add', [
            'project_id'            => $project_id,
            'sitemap'               => $sitemap_url,
            'google'                => $google,
            'yandex'                => $yandex,
            'bing'                  => $bing,
            'google_access_granted' => $google_access_granted,
            'watch'                 => $watch,
        ]);
    }

    /**
     * 启用或禁用Sitemap的更改跟踪。
     *
     * @param int $project_id 项目ID。
     * @param int $sitemap_id Sitemap文件ID。
     * @param bool $watch 新的跟踪状态(true - 启用,false - 禁用)。
     * @return array|null 来自API的解码响应。
     */
    public function update_sitemap_watch($project_id, $sitemap_id, $watch)
    {
        return $this->make_request('sitemap/update_watch', [
            'project_id' => $project_id,
            'sitemap_id' => $sitemap_id,
            'watch'      => $watch,
        ]);
    }

    /**
     * 从项目中删除Sitemap。
     *
     * @param int $project_id 项目ID。
     * @param int $sitemap_id 要删除的Sitemap文件ID。
     * @return array|null 来自API的解码响应。
     */
    public function sitemap_delete($project_id, $sitemap_id)
    {
        return $this->make_request('sitemap/delete', [
            'project_id' => $project_id,
            'sitemap_id' => $sitemap_id,
        ]);
    }

    /**
     * 执行API请求。
     *
     * @param string $endpoint 要调用的API端点。
     * @param array|true $post_data POST请求的数据。如果为true,则发送空POST。
     * @return array|null 来自API的解码JSON响应,或在出错时返回null。
     */
    private function make_request($endpoint, $post_data = [])
    {
        $ch = curl_init($this->url . $endpoint);

        if ($post_data === true) {
            curl_setopt($ch, CURLOPT_POST, 1);
        } elseif ($post_data) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
        }

        curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer " . $this->access_token]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);

        // 指定user-agent,如果出现403错误,则需要指定
        // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36');

        $result = curl_exec($ch);
        curl_close($ch);

        return json_decode($result, 1);
    }
}