Snipe-IT 技能
概述
Snipe-IT REST API 对所有有效的 HTTP 请求返回 200 OK。
请检查响应中的 .status 字段——success 或 error。
基础 URL:$SNIPEIT_URL/api/v1
核心辅助函数
bash
snipe() {
local method=${1:-GET}
local endpoint=$2
local data=${3:-}
local args=(
-s -X $method
-H Authorization: Bearer $SNIPEITAPITOKEN
-H Accept: application/json
-H Content-Type: application/json
)
[ -n $data ] && args+=(-d $data)
curl ${args[@]} ${SNIPEIT_URL}/api/v1${endpoint} | jq .
}
快捷方式
snipe_get() { snipe GET $1; }
snipe_post() { snipe POST $1 $2; }
snipe_patch() { snipe PATCH $1 $2; }
snipe_put() { snipe PUT $1 $2; }
snipe_delete() { snipe DELETE $1; }
资产(硬件)
bash
列出所有资产(带分页)
snipe_get /hardware?limit=50&offset=0
搜索资产
snipe_get /hardware?search=MacBook&limit=20
按状态标签筛选
snipe
get /hardware?statusid=2&limit=50
按ID获取资产
snipe_get /hardware/42
按资产标签获取资产
snipe_get /hardware/bytag/ASSET-001
按序列号获取资产
snipe_get /hardware/byserial/SN123456
创建资产
snipe_post /hardware {
asset_tag: ASSET-001,
model_id: 5,
status_id: 2,
name: MacBook Pro 16,
serial: SN123456,
location_id: 1,
notes: 分配给开发团队
}
更新资产(PATCH = 部分更新)
snipe_patch /hardware/42 {
name: MacBook Pro 16(已更新),
status_id: 3,
notes: 屏幕已更换
}
完全更新(PUT = 替换所有字段)
snipe_put /hardware/42 {
asset_tag: ASSET-001,
model_id: 5,
status_id: 2,
name: MacBook Pro 16,
serial: SN123456
}
删除资产
snipe_delete /hardware/42
将资产借出给用户
snipe_post /hardware/42/checkout {
checkout
totype: user,
assigned_user: 7,
note: 分配用于远程工作,
checkout_at: 2025-01-15,
expected_checkin: 2025-12-31
}
将资产借出到位置
snipe_post /hardware/42/checkout {
checkout
totype: location,
assigned_location: 3,
note: 会议室设置
}
将资产借出给另一个资产
snipe_post /hardware/42/checkout {
checkout
totype: asset,
assigned_asset: 15
}
归还资产
snipe_post /hardware/42/checkin {
note: 使用后归还,
checkin_at: 2025-06-01
}
审计资产(确认位置)
snipe_post /hardware/audit {
asset_tag: ASSET-001,
location_id: 2,
note: 季度审计时已验证
}
获取审计历史
snipe_get /hardware/audit/due
snipe_get /hardware/audit/overdue
列出借出给用户的资产
snipe_get /users/7/assets
恢复已删除的资产
snipe_post /hardware/42/restore {}
用户
bash
列出所有用户
snipe_get /users?limit=50
搜索用户
snipe_get /users?search=john&limit=20
按ID获取用户
snipe_get /users/7
获取当前API用户
snipe_get /users/me
创建用户
snipe_post /users {
first_name: John,
last_name: Doe,
username: john.doe,
email: john.doe@example.com,
password: SecurePass123!,
password_confirmation: SecurePass123!,
department_id: 2,
location_id: 1,
employee_num: EMP-001,
jobtitle: 开发者,
activated: true
}
更新用户
snipe_patch /users/7 {
department_id: 3,
jobtitle: 高级开发者
}
删除用户
snipe_delete /users/7
获取用户的资产
snipe_get /users/7/assets
获取用户的许可证
snipe_get /users/7/licenses
获取用户的配件
snipe_get /users/7/accessories
获取用户的耗材
snipe_get /users/7/consumables
许可证
bash
列出所有许可证
snipe_get /licenses?limit=50
搜索许可证
snipe_get /licenses?search=Office&limit=20
按ID获取许可证
snipe_get /licenses/3
创建许可证
snipe_post /licenses {
name: Microsoft Office 365,
serial: XXXXX-XXXXX-XXXXX,
seats: 25,
category_id: 4,
manufacturer_id: 2,
license_email: it@example.com,
purchase_date: 2025-01-01,
expiration_date: 2026-01-01,
purchase_cost: 299.99,
notes: 年度订阅
}
更新许可证
snipe_patch /licenses/3 {
seats: 30,
notes: 席位已增加
}
删除许可证
snipe_delete /licenses/3
列出许可证席位(谁借出了)
snipe_get /licenses/3/seats
将许可证席位借出给用户
snipe_post /licenses/3/seats/12/checkout {
assigned_to: 7,
note: 开发者许可证
}
归还许可证席位
snipe_delete /licenses/3/seats/12/checkin
配件
bash
列出所有配件
snipe_get /accessories?limit=50
按ID获取配件
snipe_get /accessories/8
创建配件
snipe_post /accessories {
name: USB-C 集线器,
category_id: 5,
manufacturer_id: 3,
qty: 10,
purchase_date: 2025-01-01,
purchase_cost: 49.99,
location_id: 1
}
更新配件
snipe_patch /accessories/8 {qty: 15}
删除配件
snipe_delete /accessories/8
将配件借出给用户
snipe_post /accessories/8/checkout {
assigned_to: 7,
note: 用于家庭办公室
}
归还配件
snipe_post /accessories/8/checkin {
note: 已归还
}
列出已借出的配件
snipe_get /accessories/8/checkedout
耗材
bash
列出耗材
snipe_get /consumables?limit=50
按ID获取耗材