尼日利亚政府费用 API:AI 驱动的公共服务数据

发布: (2025年12月15日 GMT+8 15:57)
6 min read
原文: Dev.to

Source: Dev.to

我构建的内容

我构建了 尼日利亚政府和公共事业费用 API,一个可直接投入生产的 REST API,提供经过验证、结构化且可追溯的尼日利亚政府费用和公共事业成本信息。它将多个尼日利亚机构的数据集中到一个可访问的端点。

在尼日利亚,公民常常难以找到以下官方服务费用的准确信息:

  • 国家身份证号码(NIN)服务
  • WAEC / NECO / JAMB 考试费用
  • 护照及身份相关流程
  • 各配电公司(DisCos)的电费
  • 其他政府监管的公共费用

问题

对大多数尼日利亚人来说,获取准确的政府费用信息非常令人沮丧。信息通常分散在 PDF、过时的网站或非官方渠道中。该 API 将这些数据集中到一个干净、开发者友好的后端,能够被应用、聊天机器人、仪表盘和 AI 代理可靠地使用。

解决方案

一个提供以下功能的单一 API:

  • 超过 90 项经过验证的政府费用,涵盖 6 大类(身份、移民、教育、电力、交通、商业)
  • 6 个官方机构:NIMC、NIS、NECO、JAMB、NERC、UNILAG
  • 完整文档,附带 JavaScript、Python 和 cURL 示例代码
  • 丰富的关联数据:每项费用都包含类别、机构和官方来源信息
  • 搜索与过滤:即时找到所需内容

API 的构建重点在于:

  • 官方数据来源
  • 可追溯性
  • 可维护性
  • 真实生产环境使用

实时 API 地址https://xmlb-8xh6-ww1h.n7e.xano.io/api:public

API 文档

该 API 采用简单且可预测的 REST 结构。

核心资源

  • 类别(如:身份与管理、教育、电力)
  • 子类别(如:NIN、NECO、JAMB、护照、DisCos)
  • 费用(可支付的单项)
  • 机构(政府部门)
  • 来源(官方文件和网站)

基础 URL

https://xmlb-8xh6-ww1h.n7e.xano.io/api:public

认证

通过查询参数传递 API 密钥:?api_key=YOUR_KEY

测试 API 密钥:nga_b6cf98a60bda43ba8cf54af9dbd87260

可用端点

1. POST /api_key/generate

生成用于访问受保护端点的 API 密钥。

curl -X POST 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/api_key/generate' \
     -H 'Content-Type: application/json' \
     --data '{"user_email":"your-email@example.com"}'

2. GET /fees

检索带分页的费用列表,可选过滤。

参数

  • category(可选)– 按类别名称/slug 过滤
  • state(可选)– 按州过滤
  • search(可选)– 在名称和描述中搜索
  • page(可选,默认 1)– 页码
  • per_page(可选,默认 20,最大 100)– 每页结果数

示例

curl 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/fees?category=identity&per_page=5'

3. GET /fees/{id}

通过 ID 获取单个费用及其所有关联信息。

示例

curl 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/fees/1?api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260'

4. GET /fees/search

按名称和描述搜索费用(最少 2 个字符)。

示例

curl 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/fees/search?q=passport&api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260'

5. GET /categories

获取所有类别及费用计数。

示例

curl 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/categories?api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260'

6. GET /metadata

获取 API 统计信息和版本信息。

示例

curl 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/metadata?api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260'

速率限制

目前未强制速率限制。已实现请求追踪,以便未来进行速率限制。

响应格式

所有响应均为 JSON。错误遵循统一格式:

{
  "code": "ERROR_CODE_TYPE",
  "message": "Human-readable error message"
}

完整文档 可在我的 GitHub 仓库 中查阅,内含完整的请求/响应示例、错误处理和集成指南。

演示

示例 1 – 生成 API 密钥

请求

curl -X POST 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/api_key/generate' \
     -H 'Content-Type: application/json' \
     --data '{"user_email":"your-email@example.com"}'

响应

{
  "success": true,
  "api_key": "nga_********************************",
  "message": "API key generated successfully. Please save this key as it provides access to the API."
}

示例 2 – 获取所有类别

请求

curl -X GET \
  'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/categories?api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260' \
  -H 'accept: application/json'

响应

[
  {
    "id": 1,
    "display_name": "Identity & Management",
    "description": "Fees related to national identity systems such as NIN",
    "fee_count": 19
  },
  {
    "id": 2,
    "display_name": "Immigration",
    "description": "Passport and visa related fees",
    "fee_count": 10
  },
  {
    "id": 3,
    "display_name": "Education",
    "description": "NECO, JAMB and related examination fees",
    "fee_count": 45
  }
]

示例 3 – 搜索 NIN 费用

请求

curl -X GET \
  'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/fees/search?q=NIN&api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260' \
  -H 'accept: application/json'

响应

[
  {
    "id": 1,
    "name": "NIN Enrolment (First Time)",
    "amount": 0,
    "currency": "NGN",
    "service_type": "Standard",
    "description": "Initial NIN enrollment is free",
    "category_name": "Identity & Management",
    "agency_name": "National Identity Management Commission",
    "subcategory_name": "NIN",
    "source_name": "NIMC"
  }
]

示例 4 – 获取费用详情

请求

curl -X GET \
  'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/fees/20?api_key=nga_b6cf98a60bda43ba8cf54af9dbd87260' \
  -H 'accept: application/json'

响应

{
  "id": 20,
  "name": "Standard Passport 32 Pages (5-Year Validity)",
  "amount": 100000,
  "currency": "NGN",
  "service_type": "Standard",
  "description": "New or Renewal",
  "subcategory": {
    "id": 3,
    "name": "Passport",
    "category": {
      "id": 2,
      "name": "Immigration",
      "description": "Passport and visa related fees"
    }
  },
  "source": {
    "id": 2,
    "name": "Nigerian Immigration Service (NIS)",
    "agency": {
      "id": 2,
      "name": "Nigeria Immigration Service",
      "website": "https://immigration.gov.ng"
    }
  }
}

代码集成示例

JavaScript

const BASE_URL = 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public';
const API_KEY = 'YOUR_API_KEY';

// 示例:获取所有类别
fetch(`${BASE_URL}/categories?api_key=${API_KEY}`)
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));

Python

import requests

BASE_URL = 'https://xmlb-8xh6-ww1h.n7e.xano.io/api:public'
API_KEY = 'YOUR_API_KEY'

# 示例:搜索护照费用
params = {'q': 'passport', 'api_key': API_KEY}
response = requests.get(f'{BASE_URL}/fees/search', params=params)
print(response.json())

cURL

curl "https://xmlb-8xh6-ww1h.n7e.xano.io/api:public/fees?category=education&api_key=YOUR_API_KEY"
Back to Blog

相关文章

阅读更多 »

开发工具中心 API

我构建的作品提交给 Xano AI 驱动的后端挑战 https://dev.to/challenges/xano-2025-11-20:生产就绪的公共 API 标题:DevTools Resourc...