- 스니펫 가시성 수준
 - 현재 사용자의 모든 스니펫 디렉터리
 - 단일 스니펫 가져오기
 - 단일 스니펫 콘텐츠
 - 스니펫 리포지터리 파일 콘텐츠
 - 새로운 스니펫 생성
 - 스니펫 업데이트
 - 스니펫 삭제
 - 모든 공개 스니펫 나열
 - 모든 스니펫 나열
 - 사용자 에이전트 세부 정보 가져오기
 
스니펫 API
스니펫 API는 스니펫에 작동합니다. 관련 API는 프로젝트 스니펫 및 스토리지 간 스니펫 이동이 있습니다.
스니펫 가시성 수준
GitLab의 스니펫은 개인, 내부, 또는 공개로 설정할 수 있습니다. 스니펫의 visibility 필드로 설정할 수 있습니다.
스니펫 가시성 수준의 유효한 값은 다음과 같습니다:
| 가시성 | 설명 | 
|---|---|
private
 | 스니펫은 스니펫 작성자에게만 표시됩니다. | 
internal
 | 스니펫은 외부 사용자를 제외한 모든 인증된 사용자에게 표시됩니다. | 
public
 | 인증 없이 스니펫에 액세스할 수 있습니다. | 
현재 사용자의 모든 스니펫 디렉터리
현재 사용자의 스니펫 디렉터리을 가져옵니다.
GET /snippets
매개변수:
| 속성 | 유형 | 필수 여부 | 설명 | 
|---|---|---|---|
per_page
 | 정수 | 아니오 | 페이지당 반환할 스니펫 수. | 
page
 | 정수 | 아니오 | 검색할 페이지입니다. | 
created_after
 | 날짜/시간 | 아니오 | 지정된 시간 이후로 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 제공됩니다.
 | 
created_before
 | 날짜/시간 | 아니오 | 지정된 시간 전에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 제공됩니다.
 | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets"
예시 응답:
[
    {
        "id": 42,
        "title": "Voluptatem iure ut qui aut et consequatur quaerat.",
        "file_name": "mclaughlin.rb",
        "description": null,
        "visibility": "internal",
        "author": {
            "id": 22,
            "name": "User 0",
            "username": "user0",
            "state": "active",
            "avatar_url": "https://www.gravatar.com/avatar/52e4ce24a915fb7e51e1ad3b57f4b00a?s=80&d=identicon",
            "web_url": "http://example.com/user0"
        },
        "updated_at": "2018-09-18T01:12:26.383Z",
        "created_at": "2018-09-18T01:12:26.383Z",
        "project_id": null,
        "web_url": "http://example.com/snippets/42",
        "raw_url": "http://example.com/snippets/42/raw"
    },
    {
        "id": 41,
        "title": "Ut praesentium non et atque.",
        "file_name": "ondrickaemard.rb",
        "description": null,
        "visibility": "internal",
        "author": {
            "id": 22,
            "name": "User 0",
            "username": "user0",
            "state": "active",
            "avatar_url": "https://www.gravatar.com/avatar/52e4ce24a915fb7e51e1ad3b57f4b00a?s=80&d=identicon",
            "web_url": "http://example.com/user0"
        },
        "updated_at": "2018-09-18T01:12:26.360Z",
        "created_at": "2018-09-18T01:12:26.360Z",
        "project_id": 1,
        "web_url": "http://example.com/gitlab-org/gitlab-test/snippets/41",
        "raw_url": "http://example.com/gitlab-org/gitlab-test/snippets/41/raw"
    }
]
단일 스니펫 가져오기
단일 스니펫을 가져옵니다.
GET /snippets/:id
매개변수:
| 속성 | 유형 | 필수 여부 | 설명 | 
|---|---|---|---|
id
 | 정수 | 예 | 검색할 스니펫의 ID. | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1"
예시 응답:
{
  "id": 1,
  "title": "test",
  "file_name": "add.rb",
  "description": "Ruby test snippet",
  "visibility": "private",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "expires_at": null,
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "project_id": null,
  "web_url": "http://example.com/snippets/1",
  "raw_url": "http://example.com/snippets/1/raw"
}
단일 스니펫 콘텐츠
단일 스니펫의 원시 콘텐츠를 가져옵니다.
GET /snippets/:id/raw
매개변수:
| 속성 | 유형 | 필수 여부 | 설명 | 
|---|---|---|---|
id
 | 정수 | 예 | 검색할 스니펫의 ID. | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1/raw"
예시 응답:
Hello World snippet
스니펫 리포지터리 파일 콘텐츠
일반 텍스트로 원시 파일 콘텐츠를 반환합니다.
GET /snippets/:id/files/:ref/:file_path/raw
매개변수:
| 속성 | 유형 | 필수 여부 | 설명 | 
|---|---|---|---|
id
 | 정수 | 예 | 검색할 스니펫의 ID. | 
ref
 | 문자열 | 예 | 태그, 브랜치 또는 커밋에 대한 참조입니다. | 
file_path
 | 문자열 | 예 | 파일의 URL 인코딩된 경로입니다. | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1/files/main/snippet%2Erb/raw"
예시 응답:
Hello World snippet
새로운 스니펫 생성
새로운 스니펫을 생성합니다.
POST /snippets
매개변수:
| 속성 | 타입 | 필수 여부 | 설명 | 
|---|---|---|---|
title
 | string | yes | 스니펫의 제목 | 
file_name
 | string | no | 사용되지 않음: 대신 files를 사용하세요. 스니펫 파일의 이름
 | 
content
 | string | no | 사용되지 않음: 대신 files를 사용하세요. 스니펫의 내용
 | 
description
 | string | no | 스니펫의 설명 | 
visibility
 | string | no | 스니펫의 가시성 | 
files
 | 해시의 배열 | no | 스니펫 파일들의 배열 | 
files:file_path
 | string | yes | 스니펫 파일의 파일 경로 | 
files:content
 | string | yes | 스니펫 파일의 내용 | 
예시 요청:
curl --request POST "https://gitlab.example.com/api/v4/snippets" \
     --header 'Content-Type: application/json' \
     --header "PRIVATE-TOKEN: <your_access_token>" \
     -d @snippet.json
위의 예시 요청에 사용된 snippet.json:
{
  "title": "This is a snippet",
  "description": "Hello World snippet",
  "visibility": "internal",
  "files": [
    {
      "content": "Hello world",
      "file_path": "test.txt"
    }
  ]
}
예시 응답:
{
  "id": 1,
  "title": "This is a snippet",
  "description": "Hello World snippet",
  "visibility": "internal",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "expires_at": null,
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "project_id": null,
  "web_url": "http://example.com/snippets/1",
  "raw_url": "http://example.com/snippets/1/raw",
  "ssh_url_to_repo": "ssh://git@gitlab.example.com:snippets/1.git",
  "http_url_to_repo": "https://gitlab.example.com/snippets/1.git",
  "file_name": "test.txt",
  "files": [
    {
      "path": "text.txt",
      "raw_url": "https://gitlab.example.com/-/snippets/1/raw/main/renamed.md"
    }
  ]
}
스니펫 업데이트
기존의 스니펫을 업데이트합니다.
PUT /snippets/:id
매개변수:
| 속성 | 타입 | 필수 여부 | 설명 | 
|---|---|---|---|
id
 | integer | yes | 업데이트할 스니펫의 ID | 
title
 | string | no | 스니펫의 제목 | 
file_name
 | string | no | 사용되지 않음: 대신 files를 사용하세요. 스니펫 파일의 이름
 | 
content
 | string | no | 사용되지 않음: 대신 files를 사용하세요. 스니펫의 내용
 | 
description
 | string | no | 스니펫의 설명 | 
visibility}
 | string | no | 스니펫의 가시성 | 
files
 | 해시의 배열 | sometimes | 스니펫 파일들의 배열. 여러 파일을 업데이트할 때 필요 | 
files:action
 | string | yes | 파일에 수행할 작업 유형 중 하나: create, update, delete, move
 | 
files:file_path
 | string | no | 스니펫 파일의 파일 경로 | 
files:previous_path
 | string | no | 이전 스니펫 파일의 경로 | 
files:content
 | string | no | 스니펫 파일의 내용 | 
예시 요청:
curl --request PUT "https://gitlab.example.com/api/v4/snippets/1" \
     --header 'Content-Type: application/json' \
     --header "PRIVATE-TOKEN: <your_access_token>" \
     -d @snippet.json
위의 예시 요청에 사용된 snippet.json:
{
  "title": "foo",
  "files": [
    {
      "action": "move",
      "previous_path": "test.txt",
      "file_path": "renamed.md"
    }
  ]
}
예시 응답:
{
  "id": 1,
  "title": "test",
  "description": "description of snippet",
  "visibility": "internal",
  "author": {
    "id": 1,
    "username": "john_smith",
    "email": "john@example.com",
    "name": "John Smith",
    "state": "active",
    "created_at": "2012-05-23T08:00:58Z"
  },
  "expires_at": null,
  "updated_at": "2012-06-28T10:52:04Z",
  "created_at": "2012-06-28T10:52:04Z",
  "project_id": null,
  "web_url": "http://example.com/snippets/1",
  "raw_url": "http://example.com/snippets/1/raw",
  "ssh_url_to_repo": "ssh://git@gitlab.example.com:snippets/1.git",
  "http_url_to_repo": "https://gitlab.example.com/snippets/1.git",
  "file_name": "renamed.md",
  "files": [
    {
      "path": "renamed.md",
      "raw_url": "https://gitlab.example.com/-/snippets/1/raw/main/renamed.md"
    }
  ]
}
스니펫 삭제
기존 스니펫을 삭제합니다.
DELETE /snippets/:id
매개변수:
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
id
 | 정수 | 예 | 삭제할 스니펫의 ID. | 
예시 요청:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1"
다음은 가능한 반환 코드입니다:
| 코드 | 설명 | 
|---|---|
204
 | 삭제가 성공적입니다. 데이터가 반환되지 않습니다. | 
404
 | 스니펫을 찾을 수 없습니다. | 
모든 공개 스니펫 나열
모든 공개 스니펫을 나열합니다.
GET /snippets/public
매개변수:
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
per_page
 | 정수 | 아니오 | 페이지당 반환할 스니펫 수. | 
page
 | 정수 | 아니오 | 검색할 페이지. | 
created_after
 | 일시 | 아니오 | 주어진 시간 이후에 만들어진 스니펫을 반환합니다. ISO 8601 형식으로 기대됩니다 (2019-03-15T08:00:00Z)
 | 
created_before
 | 일시 | 아니오 | 주어진 시간 이전에 만들어진 스니펫을 반환합니다. ISO 8601 형식으로 기대됩니다 (2019-03-15T08:00:00Z)
 | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/public?per_page=2&page=1"
예시 응답:
[
    {
        "author": {
            "avatar_url": "http://www.gravatar.com/avatar/edaf55a9e363ea263e3b981d09e0f7f7?s=80&d=identicon",
            "id": 12,
            "name": "Libby Rolfson",
            "state": "active",
            "username": "elton_wehner",
            "web_url": "http://example.com/elton_wehner"
        },
        "created_at": "2016-11-25T16:53:34.504Z",
        "file_name": "oconnerrice.rb",
        "id": 49,
        "title": "Ratione cupiditate et laborum temporibus.",
        "updated_at": "2016-11-25T16:53:34.504Z",
        "project_id": null,
        "web_url": "http://example.com/snippets/49",
        "raw_url": "http://example.com/snippets/49/raw"
    },
    {
        "author": {
            "avatar_url": "http://www.gravatar.com/avatar/36583b28626de71061e6e5a77972c3bd?s=80&d=identicon",
            "id": 16,
            "name": "Llewellyn Flatley",
            "state": "active",
            "username": "adaline",
            "web_url": "http://example.com/adaline"
        },
        "created_at": "2016-11-25T16:53:34.479Z",
        "file_name": "muellershields.rb",
        "id": 48,
        "title": "Minus similique nesciunt vel fugiat qui ullam sunt.",
        "updated_at": "2016-11-25T16:53:34.479Z",
        "project_id": null,
        "web_url": "http://example.com/snippets/48",
        "raw_url": "http://example.com/snippets/49/raw",
        "visibility": "public"
    }
]
모든 스니펫 나열
- GitLab 16.3에서 도입.
 
현재 사용자가 액세스 권한을 가지고 있는 모든 스니펫을 나열합니다. 관리자 또는 감사자 액세스 수준을 가진 사용자는 모든 스니펫(개인 및 프로젝트)을 볼 수 있습니다.
GET /snippets/all
매개변수:
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
created_after
 | 일시 | 아니오 | 주어진 시간 이후에 만들어진 스니펫을 반환합니다. ISO 8601 형식으로 기대됩니다 (2019-03-15T08:00:00Z).
 | 
created_before
 | 일시 | 아니오 | 주어진 시간 이전에 만들어진 스니펫을 반환합니다. ISO 8601 형식으로 기대됩니다 (2019-03-15T08:00:00Z).
 | 
page
 | 정수 | 아니오 | 검색할 페이지. | 
per_page
 | 정수 | 아니오 | 페이지당 반환할 스니펫 수. | 
repository_storage
 | 문자열 | 아니오 | 스니펫에서 사용하는 리포지터리 스토리지로 필터링합니다 (관리자 전용). GitLab 16.3에서 도입. | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/all?per_page=2&page=1"
예시 응답:
[
  {
    "id": 113,
    "title": "내부 프로젝트 스니펫",
    "description": null,
    "visibility": "internal",
    "author": {
      "id": 17,
      "username": "tim_kreiger",
      "name": "Tim Kreiger",
      "state": "active",
      "avatar_url": "http://www.gravatar.com/avatar/edaf55a9e363ea263e3b981d09e0f7f7?s=80&d=identicon",
      "web_url": "http://example.com/tim_kreiger"
    },
    "created_at": "2023-08-03T10:21:02.480Z",
    "updated_at": "2023-08-03T10:21:02.480Z",
    "project_id": 35,
    "web_url": "http://example.com/tim_kreiger/internal_project/-/snippets/113",
    "raw_url": "http://example.com/tim_kreiger/internal_project/-/snippets/113/raw",
    "file_name": "",
    "files": [],
    "repository_storage": "default"
  },
  {
    "id": 112,
    "title": "개인 스니펫",
    "description": null,
    "visibility": "private",
    "author": {
      "id": 1,
      "username": "root",
      "name": "Administrator",
      "state": "active",
      "avatar_url": "http://www.gravatar.com/avatar/edaf55a9e363ea263e3b981d09e0f7f7?s=80&d=identicon",
      "web_url": "http://example.com/root"
    },
    "created_at": "2023-08-03T10:20:59.994Z",
    "updated_at": "2023-08-03T10:20:59.994Z",
    "project_id": null,
    "web_url": "http://example.com/-/snippets/112",
    "raw_url": "http://example.com/-/snippets/112/raw",
    "file_name": "",
    "files": [],
    "repository_storage": "default"
  },
  {
    "id": 111,
    "title": "공개 개인 스니펫",
    "description": null,
    "visibility": "public",
    "author": {
      "id": 17,
      "username": "tim_kreiger",
      "name": "Tim Kreiger",
      "state": "active",
      "avatar_url": "http://www.gravatar.com/avatar/edaf55a9e363ea263e3b981d09e0f7f7?s=80&d=identicon",
      "web_url": "http://example.com/tim_kreiger"
    },
    "created_at": "2023-08-03T10:21:01.312Z",
    "updated_at": "2023-08-03T10:21:01.312Z",
    "project_id": null,
    "web_url": "http://example.com/-/snippets/111",
    "raw_url": "http://example.com/-/snippets/111/raw",
    "file_name": "",
    "files": [],
    "repository_storage": "default"
  }
]
사용자 에이전트 세부 정보 가져오기
GET /snippets/:id/user_agent_detail
| 속성 | 유형 | 필수여부 | 설명 | 
|---|---|---|---|
id
 | 정수 | 예 | 스니펫의 ID입니다. | 
예시 요청:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1/user_agent_detail"
예시 응답:
{
  "user_agent": "AppleWebKit/537.36",
  "ip_address": "127.0.0.1",
  "akismet_submitted": false
}
도움말