InfoGrab DocsInfoGrab Docs

프로젝트 스니펫

요약

이 API로 프로젝트 스니펫을 관리합니다. 지정한 프로젝트의 모든 스니펫을 조회합니다. 요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다. 지정한 프로젝트 스니펫을 조회합니다. 프로젝트 스니펫을 생성합니다. 스니펫 생성은 인증된 사용자마다 시간당 300건으로 속도가 제한됩니다.

이 API로 프로젝트 스니펫을 관리합니다. 관련 API로 개인 스니펫과 스토리지 간 스니펫 이동이 있습니다.

프로젝트의 모든 스니펫 조회#

지정한 프로젝트의 모든 스니펫을 조회합니다.

GET /projects/:id/snippets

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets"

응답 예시:

[
  {
    "id": 1,
    "title": "test",
    "file_name": "add.rb",
    "description": "Ruby test snippet",
    "author": {
      "id": 1,
      "username": "john_smith",
      "email": "john@example.com",
      "name": "John Smith",
      "state": "active",
      "created_at": "2012-05-23T08:00:58Z"
    },
    "updated_at": "2012-06-28T10:52:04Z",
    "created_at": "2012-06-28T10:52:04Z",
    "imported": false,
    "imported_from": "none",
    "project_id": 1,
    "web_url": "http://example.com/example/example/snippets/1",
    "raw_url": "http://example.com/example/example/snippets/1/raw",
    "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/1.git",
    "http_url_to_repo": "http://example.com/example/example/snippets/1.git"
  },
  {
    "id": 3,
    "title": "Configuration helper",
    "file_name": "config.yml",
    "description": "YAML configuration snippet",
    "author": {
      "id": 2,
      "username": "jane_doe",
      "email": "jane@example.com",
      "name": "Jane Doe",
      "state": "active",
      "created_at": "2013-02-15T10:30:20Z"
    },
    "updated_at": "2013-03-10T14:15:30Z",
    "created_at": "2013-03-01T09:45:12Z",
    "imported": false,
    "imported_from": "none",
    "project_id": 1,
    "web_url": "http://example.com/example/example/snippets/3",
    "raw_url": "http://example.com/example/example/snippets/3/raw",
    "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/3.git",
    "http_url_to_repo": "http://example.com/example/example/snippets/3.git"
  }
]

스니펫 조회#

지정한 프로젝트 스니펫을 조회합니다.

GET /projects/:id/snippets/:snippet_id

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2"

응답 예시:

{
  "id": 2,
  "title": "test",
  "file_name": "add.rb",
  "description": "Ruby test snippet",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "imported": false,
  "imported_from": "none",
  "project_id": 1,
  "web_url": "http://example.com/example/example/snippets/2",
  "raw_url": "http://example.com/example/example/snippets/2/raw",
  "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/2.git",
  "http_url_to_repo": "http://example.com/example/example/snippets/2.git"
}

스니펫 생성#

프로젝트 스니펫을 생성합니다. 사용자에게 스니펫을 생성할 권한이 있어야 합니다.

스니펫 생성은 인증된 사용자마다 시간당 300건으로 속도가 제한됩니다. 이 제한은 이 엔드포인트와 개인 스니펫 생성, 그리고 GitLab UI가 사용하는 createSnippet GraphQL 뮤테이션이 함께 사용합니다. 자세한 내용은 구성할 수 없는 속도 제한을 참고합니다.

POST /projects/:id/snippets

지원되는 속성:

속성 유형 필수 설명
files array of hashes 예 스니펫 파일의 배열입니다.
files:content string 예 스니펫 파일의 콘텐츠입니다.
files:file_path string 예 스니펫 파일의 파일 경로입니다.
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
title string 예 스니펫의 제목입니다.
content string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫의 콘텐츠입니다.
description string 아니요 스니펫의 설명입니다.
file_name string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫 파일의 이름입니다.
visibility string 아니요 스니펫의 공개 범위 수준입니다. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

요청에 성공하면 201 Created와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --data '{"title": "Example Snippet Title", "description": "More verbose snippet description", "visibility": "private", "files": [{"file_path": "example.txt", "content": "source code \n with multiple lines\n"}]}' \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets"

응답 예시:

{
  "id": 1,
  "title": "Example Snippet Title",
  "file_name": "example.txt",
  "description": "More verbose snippet description",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "imported": false,
  "imported_from": "none",
  "project_id": 1,
  "web_url": "http://example.com/example/example/snippets/1",
  "raw_url": "http://example.com/example/example/snippets/1/raw",
  "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/1.git",
  "http_url_to_repo": "http://example.com/example/example/snippets/1.git"
}

스니펫 업데이트#

지정한 프로젝트 스니펫을 업데이트합니다. 사용자에게 기존 스니펫을 변경할 권한이 있어야 합니다.

파일이 여러 개인 스니펫을 업데이트할 때는 files 속성을 사용해야 합니다.

PUT /projects/:id/snippets/:snippet_id

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.
files:action string Conditionally 파일에 수행할 작업의 유형입니다. create, update, delete, move 중 하나입니다. files 속성을 사용할 때 필수입니다.
content string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫의 콘텐츠입니다.
description string 아니요 스니펫의 설명입니다.
file_name string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫 파일의 이름입니다.
files array of hashes 아니요 스니펫 파일의 배열입니다.
files:content string 아니요 스니펫 파일의 콘텐츠입니다.
files:file_path string 아니요 스니펫 파일의 파일 경로입니다.
files:previous_path string 아니요 스니펫 파일의 이전 경로입니다.
title string 아니요 스니펫의 제목입니다.
visibility string 아니요 스니펫의 공개 범위 수준입니다. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --data '{"title": "Updated Snippet Title", "description": "More verbose snippet description", "visibility": "private", "files": [{"action": "update", "file_path": "example.txt", "content": "updated source code \n with multiple lines\n"}]}' \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2"

응답 예시:

{
  "id": 2,
  "title": "Updated Snippet Title",
  "file_name": "example.txt",
  "description": "More verbose snippet description",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "imported": false,
  "imported_from": "none",
  "project_id": 1,
  "web_url": "http://example.com/example/example/snippets/2",
  "raw_url": "http://example.com/example/example/snippets/2/raw",
  "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/2.git",
  "http_url_to_repo": "http://example.com/example/example/snippets/2.git"
}

스니펫 삭제#

지정한 프로젝트 스니펫을 삭제합니다. 작업에 성공하면 204 No Content 상태 코드를, 리소스를 찾지 못하면 404를 반환합니다.

DELETE /projects/:id/snippets/:snippet_id

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청 예시:

curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2"

스니펫 콘텐츠 조회#

프로젝트 스니펫의 원본을 일반 텍스트로 조회합니다.

GET /projects/:id/snippets/:snippet_id/raw

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2/raw"

스니펫 리포지터리 파일 콘텐츠 조회#

원본 파일 콘텐츠를 일반 텍스트로 조회합니다.

GET /projects/:id/snippets/:snippet_id/files/:ref/:file_path/raw

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
file_path string 예 URL 인코딩된 파일 경로입니다. 예: snippet%2Erb.
ref string 예 브랜치, 태그 또는 커밋의 이름입니다. 예: main.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2/files/master/snippet%2Erb/raw"

사용자 에이전트 정보 조회#

지정한 스니펫의 사용자 에이전트 정보를 조회합니다. 관리자 액세스 권한이 있는 사용자만 사용할 수 있습니다.

GET /projects/:id/snippets/:snippet_id/user_agent_detail

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 스니펫의 ID 입니다.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
akismet_submitted boolean true 이면 해당 스니펫이 스팸 탐지를 위해 Akismet에 제출된 것입니다.
ip_address string 스니펫을 생성한 사용자의 IP 주소입니다.
user_agent string 스니펫 생성에 사용된 브라우저의 사용자 에이전트 문자열입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2/user_agent_detail"

응답 예시:

{
  "user_agent": "AppleWebKit/537.36",
  "ip_address": "127.0.0.1",
  "akismet_submitted": false
}

프로젝트 스니펫

GitLab v19.5
Tier: Free, Premium, Ultimate
Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
원문 보기

요약

이 API로 프로젝트 스니펫을 관리합니다. 지정한 프로젝트의 모든 스니펫을 조회합니다. 요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다. 지정한 프로젝트 스니펫을 조회합니다. 프로젝트 스니펫을 생성합니다. 스니펫 생성은 인증된 사용자마다 시간당 300건으로 속도가 제한됩니다.

이 API로 프로젝트 스니펫을 관리합니다. 관련 API로 개인 스니펫과 스토리지 간 스니펫 이동이 있습니다.

프로젝트의 모든 스니펫 조회#

지정한 프로젝트의 모든 스니펫을 조회합니다.

GET /projects/:id/snippets

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets"

응답 예시:

[
  {
    "id": 1,
    "title": "test",
    "file_name": "add.rb",
    "description": "Ruby test snippet",
    "author": {
      "id": 1,
      "username": "john_smith",
      "email": "john@example.com",
      "name": "John Smith",
      "state": "active",
      "created_at": "2012-05-23T08:00:58Z"
    },
    "updated_at": "2012-06-28T10:52:04Z",
    "created_at": "2012-06-28T10:52:04Z",
    "imported": false,
    "imported_from": "none",
    "project_id": 1,
    "web_url": "http://example.com/example/example/snippets/1",
    "raw_url": "http://example.com/example/example/snippets/1/raw",
    "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/1.git",
    "http_url_to_repo": "http://example.com/example/example/snippets/1.git"
  },
  {
    "id": 3,
    "title": "Configuration helper",
    "file_name": "config.yml",
    "description": "YAML configuration snippet",
    "author": {
      "id": 2,
      "username": "jane_doe",
      "email": "jane@example.com",
      "name": "Jane Doe",
      "state": "active",
      "created_at": "2013-02-15T10:30:20Z"
    },
    "updated_at": "2013-03-10T14:15:30Z",
    "created_at": "2013-03-01T09:45:12Z",
    "imported": false,
    "imported_from": "none",
    "project_id": 1,
    "web_url": "http://example.com/example/example/snippets/3",
    "raw_url": "http://example.com/example/example/snippets/3/raw",
    "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/3.git",
    "http_url_to_repo": "http://example.com/example/example/snippets/3.git"
  }
]

스니펫 조회#

지정한 프로젝트 스니펫을 조회합니다.

GET /projects/:id/snippets/:snippet_id

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2"

응답 예시:

{
  "id": 2,
  "title": "test",
  "file_name": "add.rb",
  "description": "Ruby test snippet",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "imported": false,
  "imported_from": "none",
  "project_id": 1,
  "web_url": "http://example.com/example/example/snippets/2",
  "raw_url": "http://example.com/example/example/snippets/2/raw",
  "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/2.git",
  "http_url_to_repo": "http://example.com/example/example/snippets/2.git"
}

스니펫 생성#

프로젝트 스니펫을 생성합니다. 사용자에게 스니펫을 생성할 권한이 있어야 합니다.

스니펫 생성은 인증된 사용자마다 시간당 300건으로 속도가 제한됩니다. 이 제한은 이 엔드포인트와 개인 스니펫 생성, 그리고 GitLab UI가 사용하는 createSnippet GraphQL 뮤테이션이 함께 사용합니다. 자세한 내용은 구성할 수 없는 속도 제한을 참고합니다.

POST /projects/:id/snippets

지원되는 속성:

속성 유형 필수 설명
files array of hashes 예 스니펫 파일의 배열입니다.
files:content string 예 스니펫 파일의 콘텐츠입니다.
files:file_path string 예 스니펫 파일의 파일 경로입니다.
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
title string 예 스니펫의 제목입니다.
content string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫의 콘텐츠입니다.
description string 아니요 스니펫의 설명입니다.
file_name string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫 파일의 이름입니다.
visibility string 아니요 스니펫의 공개 범위 수준입니다. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

요청에 성공하면 201 Created와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --data '{"title": "Example Snippet Title", "description": "More verbose snippet description", "visibility": "private", "files": [{"file_path": "example.txt", "content": "source code \n with multiple lines\n"}]}' \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets"

응답 예시:

{
  "id": 1,
  "title": "Example Snippet Title",
  "file_name": "example.txt",
  "description": "More verbose snippet description",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "imported": false,
  "imported_from": "none",
  "project_id": 1,
  "web_url": "http://example.com/example/example/snippets/1",
  "raw_url": "http://example.com/example/example/snippets/1/raw",
  "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/1.git",
  "http_url_to_repo": "http://example.com/example/example/snippets/1.git"
}

스니펫 업데이트#

지정한 프로젝트 스니펫을 업데이트합니다. 사용자에게 기존 스니펫을 변경할 권한이 있어야 합니다.

파일이 여러 개인 스니펫을 업데이트할 때는 files 속성을 사용해야 합니다.

PUT /projects/:id/snippets/:snippet_id

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.
files:action string Conditionally 파일에 수행할 작업의 유형입니다. create, update, delete, move 중 하나입니다. files 속성을 사용할 때 필수입니다.
content string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫의 콘텐츠입니다.
description string 아니요 스니펫의 설명입니다.
file_name string 아니요 더 이상 사용되지 않습니다. 대신 files를 사용합니다. 스니펫 파일의 이름입니다.
files array of hashes 아니요 스니펫 파일의 배열입니다.
files:content string 아니요 스니펫 파일의 콘텐츠입니다.
files:file_path string 아니요 스니펫 파일의 파일 경로입니다.
files:previous_path string 아니요 스니펫 파일의 이전 경로입니다.
title string 아니요 스니펫의 제목입니다.
visibility string 아니요 스니펫의 공개 범위 수준입니다. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
author.created_at string 작성자 계정이 생성된 날짜 및 시각입니다.
author.email string 스니펫 작성자의 이메일 주소입니다.
author.id integer 스니펫 작성자의 ID 입니다.
author.name string 스니펫 작성자의 표시 이름입니다.
author.state string 작성자 계정의 상태입니다.
author.username string 스니펫 작성자의 사용자 이름입니다.
created_at string 스니펫이 생성된 날짜 및 시각이며, ISO 8601 형식입니다.
description string 스니펫의 설명입니다.
file_name string 스니펫 파일의 이름입니다.
http_url_to_repo string 스니펫 리포지터리의 HTTP URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
id integer 스니펫의 ID 입니다.
imported boolean true 이면 해당 스니펫은 가져오기로 생성된 것입니다.
imported_from string 스니펫을 가져온 경우 그 가져오기 원본입니다.
project_id integer 스니펫이 속한 프로젝트의 ID 입니다.
raw_url string 원본 스니펫 콘텐츠로 바로 연결되는 URL 입니다.
ssh_url_to_repo string 스니펫 리포지터리의 SSH URL입니다. 스니펫 리포지터리가 있는 경우에만 반환됩니다.
title string 스니펫의 제목입니다.
updated_at string 스니펫이 마지막으로 업데이트된 날짜 및 시각이며, ISO 8601 형식입니다.
web_url string GitLab 웹 인터페이스에서 스니펫을 볼 수 있는 URL 입니다.

요청 예시:

curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --data '{"title": "Updated Snippet Title", "description": "More verbose snippet description", "visibility": "private", "files": [{"action": "update", "file_path": "example.txt", "content": "updated source code \n with multiple lines\n"}]}' \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2"

응답 예시:

{
  "id": 2,
  "title": "Updated Snippet Title",
  "file_name": "example.txt",
  "description": "More verbose snippet description",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "imported": false,
  "imported_from": "none",
  "project_id": 1,
  "web_url": "http://example.com/example/example/snippets/2",
  "raw_url": "http://example.com/example/example/snippets/2/raw",
  "ssh_url_to_repo": "ssh://git@example.com:example/example/snippets/2.git",
  "http_url_to_repo": "http://example.com/example/example/snippets/2.git"
}

스니펫 삭제#

지정한 프로젝트 스니펫을 삭제합니다. 작업에 성공하면 204 No Content 상태 코드를, 리소스를 찾지 못하면 404를 반환합니다.

DELETE /projects/:id/snippets/:snippet_id

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청 예시:

curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2"

스니펫 콘텐츠 조회#

프로젝트 스니펫의 원본을 일반 텍스트로 조회합니다.

GET /projects/:id/snippets/:snippet_id/raw

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2/raw"

스니펫 리포지터리 파일 콘텐츠 조회#

원본 파일 콘텐츠를 일반 텍스트로 조회합니다.

GET /projects/:id/snippets/:snippet_id/files/:ref/:file_path/raw

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
file_path string 예 URL 인코딩된 파일 경로입니다. 예: snippet%2Erb.
ref string 예 브랜치, 태그 또는 커밋의 이름입니다. 예: main.
snippet_id integer 예 프로젝트 스니펫의 ID 입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2/files/master/snippet%2Erb/raw"

사용자 에이전트 정보 조회#

지정한 스니펫의 사용자 에이전트 정보를 조회합니다. 관리자 액세스 권한이 있는 사용자만 사용할 수 있습니다.

GET /projects/:id/snippets/:snippet_id/user_agent_detail

지원되는 속성:

속성 유형 필수 설명
id integer or string 예 프로젝트의 ID 또는 URL 인코딩된 경로.
snippet_id integer 예 스니펫의 ID 입니다.

요청에 성공하면 200 OK와 다음 응답 속성을 반환합니다.

속성 유형 설명
akismet_submitted boolean true 이면 해당 스니펫이 스팸 탐지를 위해 Akismet에 제출된 것입니다.
ip_address string 스니펫을 생성한 사용자의 IP 주소입니다.
user_agent string 스니펫 생성에 사용된 브라우저의 사용자 에이전트 문자열입니다.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/snippets/2/user_agent_detail"

응답 예시:

{
  "user_agent": "AppleWebKit/537.36",
  "ip_address": "127.0.0.1",
  "akismet_submitted": false
}