Skip to content

POST /api/v1/projects

POST/api/v1/projects

创建项目(创建者自动成为 owner)

projectoperationId: projectCreate

请求体

请求数据

Content-Type · application/json

{
  "type": "object",
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string",
      "description": "去空格后非空,长度不超过 100"
    },
    "slug": {
      "type": "string",
      "description": "缺省时由 name 生成,仅小写字母/数字/连字符"
    },
    "description": {
      "type": "string"
    }
  }
}

请求示例

cURL
curl -X POST 'http://localhost:8080/api/v1/projects' \
  -H 'Accept: application/json' \
  -H 'X-API-Key: <PROJECT_API_KEY>'
# 也可使用登录会话:-H 'Authorization: Bearer <JWT>'
JavaScript
const res = await fetch('http://localhost:8080/api/v1/projects', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'X-API-Key': '<PROJECT_API_KEY>'
  },
});
const data = await res.json();
Python
import requests

res = requests.post(
    'http://localhost:8080/api/v1/projects',
    headers={'Accept': 'application/json', 'X-API-Key': '<PROJECT_API_KEY>'}
)
print(res.json())

响应

201创建成功,返回项目对象

application/json

{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "name": {
      "type": "string"
    },
    "slug": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "created_by": {
      "type": "string",
      "format": "uuid"
    },
    "status": {
      "type": "string"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  }
}
400请求参数错误

application/json

{
  "type": "object",
  "properties": {
    "code": {
      "type": "string",
      "example": "not_found"
    },
    "message": {
      "type": "string",
      "example": "资源不存在"
    }
  }
}
401未认证或凭据无效

application/json

{
  "type": "object",
  "properties": {
    "code": {
      "type": "string",
      "example": "not_found"
    },
    "message": {
      "type": "string",
      "example": "资源不存在"
    }
  }
}

在线调试

在线调试
凭证仅保存在当前页面内存中
自定义请求 Header