You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用GitLab API创建带指定权限范围的令牌时提示scope无效

解决GitLab API创建个人访问令牌时的"scopes does not have a valid value"错误

出现这个错误通常有两个常见原因,对应解决方案如下:

1. 确认GitLab服务器版本兼容性

read_repository这个权限范围是GitLab 10.0版本才引入的,如果你的GitLab服务器版本低于这个版本,会触发该错误。先检查服务器的版本号,必要时升级GitLab。

2. 修正请求参数的传递格式

curl通过--data传递数组参数时,部分环境下scopes[]的格式无法被GitLab API正确解析,你可以尝试以下两种修正方式:

方式一:调整单个scope的参数格式

把scopes[]=read_repository改为scopes=read_repository,命令如下:

curl --request POST \
  --header "PRIVATE-TOKEN: glpat-" \
  --data "name=test-token-short-ttl" \
  --data "scopes=read_repository" \
  --data "expires_at=2025-08-06" \
  --url "https://gitlab.example.ru/api/v4/user/personal_access_tokens"

如果需要多个权限范围,用逗号分隔即可,比如scopes=read_repository,write_repository。

方式二:使用JSON格式发送请求体(推荐)

用JSON格式传递参数能避免大部分解析问题,命令如下:

curl --request POST \
  --header "PRIVATE-TOKEN: glpat-" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "test-token-short-ttl",
    "scopes": ["read_repository"],
    "expires_at": "2025-08-06"
  }' \
  --url "https://gitlab.example.ru/api/v4/user/personal_access_tokens"

添加多个权限范围时,直接在JSON数组中追加元素即可,比如"scopes": ["read_repository", "write_repository"]。

内容的提问来源于stack exchange,提问作者Overlord

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 13:42:38