InfoGrab Docs

Snippets API

요약

이 API를 사용하여 스니펫을 관리하세요. 현재 사용자의 스니펫 목록을 가져옵니다. 성공하면 200 OK와 다음 응답 속성을 반환합니다: 단일 스니펫의 원시 콘텐츠를 가져옵니다. 성공하면 200 OK와 스니펫의 원시 콘텐츠를 반환합니다.

이 API를 사용하여 스니펫을 관리하세요. 프로젝트 스니펫스니펫 간 스토리지 이동에 대한 관련 API도 있습니다.

현재 사용자의 모든 스니펫 목록 조회#

현재 사용자의 스니펫 목록을 가져옵니다.

GET /snippets

지원되는 속성:

속성 유형 필수 설명
created_after 날짜시간 아니오 주어진 시간 이후에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
created_before 날짜시간 아니오 주어진 시간 이전에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
page 정수 아니오 조회할 페이지.
per_page 정수 아니오 페이지당 반환할 스니펫 수.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
file_name 문자열 스니펫 파일 이름.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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",
        "imported": false,
        "imported_from": "none",
        "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",
        "imported": false,
        "imported_from": "none",
        "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.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
expires_at 문자열 스니펫이 만료되는 날짜 및 시간.
file_name 문자열 스니펫 파일 이름.
http_url_to_repo 문자열 스니펫 저장소의 HTTP URL.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
ssh_url_to_repo 문자열 스니펫 저장소의 SSH URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

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

응답 예시:

{
  "id": 1,
  "title": "test",
  "file_name": "add.rb",
  "description": "Ruby test snippet",
  "visibility": "private",
  "imported": false,
  "imported_from": "none",
  "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.

성공하면 200 OK와 스니펫의 원시 콘텐츠를 반환합니다.

요청 예시:

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

응답 예시:

Hello World snippet

스니펫 저장소 파일 콘텐츠#

평문으로 원시 파일 콘텐츠를 반환합니다.

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

지원되는 속성:

속성 유형 필수 설명
file_path 문자열 URL 인코딩된 파일 경로.
id 정수 조회할 스니펫의 ID.
ref 문자열 태그, 브랜치 또는 커밋에 대한 참조.

성공하면 200 OK와 원시 파일 콘텐츠를 반환합니다.

요청 예시:

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

응답 예시:

Hello World snippet

스니펫 생성#

새 스니펫을 생성합니다.

Note

사용자는 새 스니펫을 생성할 권한이 있어야 합니다.

POST /snippets

지원되는 속성:

속성 유형 필수 설명
files:content 문자열 스니펫 파일의 콘텐츠.
files:file_path 문자열 스니펫 파일의 파일 경로.
title 문자열 스니펫의 제목.
content 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫의 콘텐츠.
description 문자열 아니오 스니펫에 대한 설명.
file_name 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫 파일의 이름.
files 해시 배열 아니오 스니펫 파일 배열.
visibility 문자열 아니오 스니펫의 공개 범위 수준. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

성공하면 201 Created와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
expires_at 문자열 스니펫이 만료되는 날짜 및 시간.
file_name 문자열 스니펫 파일 이름.
files 배열 스니펫 파일 배열.
http_url_to_repo 문자열 스니펫 저장소의 HTTP URL.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
ssh_url_to_repo 문자열 스니펫 저장소의 SSH URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

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",
  "imported": false,
  "imported_from": "none",
  "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"
    }
  ]
}

스니펫 업데이트#

기존 스니펫을 업데이트합니다.

Note

사용자는 기존 스니펫을 변경할 권한이 있어야 합니다.

PUT /snippets/:id

지원되는 속성:

속성 유형 필수 설명
id 정수 업데이트할 스니펫의 ID.
files:action 문자열 파일에 수행할 액션 유형: create, update, delete, move 중 하나.
content 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫의 콘텐츠.
description 문자열 아니오 스니펫에 대한 설명.
file_name 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫 파일의 이름.
files 해시 배열 조건부 스니펫 파일 배열. 여러 파일이 있는 스니펫을 업데이트할 때 필수입니다.
files:content 문자열 아니오 스니펫 파일의 콘텐츠.
files:file_path 문자열 아니오 스니펫 파일의 파일 경로.
files:previous_path 문자열 아니오 스니펫 파일의 이전 경로.
title 문자열 아니오 스니펫의 제목.
visibility 문자열 아니오 스니펫의 공개 범위 수준. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
expires_at 문자열 스니펫이 만료되는 날짜 및 시간.
file_name 문자열 스니펫 파일 이름.
files 배열 스니펫 파일 배열.
http_url_to_repo 문자열 스니펫 저장소의 HTTP URL.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
ssh_url_to_repo 문자열 스니펫 저장소의 SSH URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

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",
  "imported": false,
  "imported_from": "none",
  "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>" \
  --url "https://gitlab.example.com/api/v4/snippets/1"

가능한 반환 코드:

코드 설명
204 삭제가 성공했습니다. 데이터가 반환되지 않습니다.
404 스니펫을 찾을 수 없습니다.

모든 공개 스니펫 목록 조회#

모든 공개 스니펫을 나열합니다.

GET /snippets/public

지원되는 속성:

속성 유형 필수 설명
created_after 날짜시간 아니오 주어진 시간 이후에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
created_before 날짜시간 아니오 주어진 시간 이전에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
page 정수 아니오 조회할 페이지.
per_page 정수 아니오 페이지당 반환할 스니펫 수.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
file_name 문자열 스니펫 파일 이름.
id 정수 스니펫의 ID.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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에서 도입되었습니다.

현재 사용자가 접근할 수 있는 모든 스니펫을 나열합니다. Administrator 또는 Auditor 접근 수준의 사용자는 모든 스니펫(개인 및 프로젝트 모두)을 볼 수 있습니다.

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에서 도입되었습니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
file_name 문자열 스니펫 파일 이름.
files 배열 스니펫 파일 배열.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
repository_storage 문자열 스니펫이 사용하는 저장소 스토리지.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/snippets/all?per_page=2&page=1"

응답 예시:

[
  {
    "id": 113,
    "title": "Internal Project Snippet",
    "description": null,
    "visibility": "internal",
    "imported": false,
    "imported_from": "none",
    "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": "Private Personal Snippet",
    "description": null,
    "visibility": "private",
    "imported": false,
    "imported_from": "none",
    "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": "Public Personal Snippet",
    "description": null,
    "visibility": "public",
    "imported": false,
    "imported_from": "none",
    "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"
  }
]

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

Note

관리자만 사용 가능합니다.

GET /snippets/:id/user_agent_detail

지원되는 속성:

속성 유형 필수 설명
id 정수 스니펫의 ID.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
akismet_submitted 불리언 true이면 세부 정보가 Akismet에 제출되었습니다.
ip_address 문자열 스니펫 생성에 사용된 IP 주소.
user_agent 문자열 스니펫 생성에 사용된 사용자 에이전트 문자열.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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
}

Snippets API

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

이 API를 사용하여 스니펫을 관리하세요. 현재 사용자의 스니펫 목록을 가져옵니다. 성공하면 200 OK와 다음 응답 속성을 반환합니다: 단일 스니펫의 원시 콘텐츠를 가져옵니다. 성공하면 200 OK와 스니펫의 원시 콘텐츠를 반환합니다.

이 API를 사용하여 스니펫을 관리하세요. 프로젝트 스니펫스니펫 간 스토리지 이동에 대한 관련 API도 있습니다.

현재 사용자의 모든 스니펫 목록 조회#

현재 사용자의 스니펫 목록을 가져옵니다.

GET /snippets

지원되는 속성:

속성 유형 필수 설명
created_after 날짜시간 아니오 주어진 시간 이후에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
created_before 날짜시간 아니오 주어진 시간 이전에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
page 정수 아니오 조회할 페이지.
per_page 정수 아니오 페이지당 반환할 스니펫 수.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
file_name 문자열 스니펫 파일 이름.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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",
        "imported": false,
        "imported_from": "none",
        "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",
        "imported": false,
        "imported_from": "none",
        "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.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
expires_at 문자열 스니펫이 만료되는 날짜 및 시간.
file_name 문자열 스니펫 파일 이름.
http_url_to_repo 문자열 스니펫 저장소의 HTTP URL.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
ssh_url_to_repo 문자열 스니펫 저장소의 SSH URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

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

응답 예시:

{
  "id": 1,
  "title": "test",
  "file_name": "add.rb",
  "description": "Ruby test snippet",
  "visibility": "private",
  "imported": false,
  "imported_from": "none",
  "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.

성공하면 200 OK와 스니펫의 원시 콘텐츠를 반환합니다.

요청 예시:

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

응답 예시:

Hello World snippet

스니펫 저장소 파일 콘텐츠#

평문으로 원시 파일 콘텐츠를 반환합니다.

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

지원되는 속성:

속성 유형 필수 설명
file_path 문자열 URL 인코딩된 파일 경로.
id 정수 조회할 스니펫의 ID.
ref 문자열 태그, 브랜치 또는 커밋에 대한 참조.

성공하면 200 OK와 원시 파일 콘텐츠를 반환합니다.

요청 예시:

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

응답 예시:

Hello World snippet

스니펫 생성#

새 스니펫을 생성합니다.

Note

사용자는 새 스니펫을 생성할 권한이 있어야 합니다.

POST /snippets

지원되는 속성:

속성 유형 필수 설명
files:content 문자열 스니펫 파일의 콘텐츠.
files:file_path 문자열 스니펫 파일의 파일 경로.
title 문자열 스니펫의 제목.
content 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫의 콘텐츠.
description 문자열 아니오 스니펫에 대한 설명.
file_name 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫 파일의 이름.
files 해시 배열 아니오 스니펫 파일 배열.
visibility 문자열 아니오 스니펫의 공개 범위 수준. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

성공하면 201 Created와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
expires_at 문자열 스니펫이 만료되는 날짜 및 시간.
file_name 문자열 스니펫 파일 이름.
files 배열 스니펫 파일 배열.
http_url_to_repo 문자열 스니펫 저장소의 HTTP URL.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
ssh_url_to_repo 문자열 스니펫 저장소의 SSH URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

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",
  "imported": false,
  "imported_from": "none",
  "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"
    }
  ]
}

스니펫 업데이트#

기존 스니펫을 업데이트합니다.

Note

사용자는 기존 스니펫을 변경할 권한이 있어야 합니다.

PUT /snippets/:id

지원되는 속성:

속성 유형 필수 설명
id 정수 업데이트할 스니펫의 ID.
files:action 문자열 파일에 수행할 액션 유형: create, update, delete, move 중 하나.
content 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫의 콘텐츠.
description 문자열 아니오 스니펫에 대한 설명.
file_name 문자열 아니오 더 이상 사용되지 않음: 대신 files를 사용하세요. 스니펫 파일의 이름.
files 해시 배열 조건부 스니펫 파일 배열. 여러 파일이 있는 스니펫을 업데이트할 때 필수입니다.
files:content 문자열 아니오 스니펫 파일의 콘텐츠.
files:file_path 문자열 아니오 스니펫 파일의 파일 경로.
files:previous_path 문자열 아니오 스니펫 파일의 이전 경로.
title 문자열 아니오 스니펫의 제목.
visibility 문자열 아니오 스니펫의 공개 범위 수준. 가능한 값: public, private, internal. GitLab.com에서는 internal 값을 사용할 수 없습니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
expires_at 문자열 스니펫이 만료되는 날짜 및 시간.
file_name 문자열 스니펫 파일 이름.
files 배열 스니펫 파일 배열.
http_url_to_repo 문자열 스니펫 저장소의 HTTP URL.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
ssh_url_to_repo 문자열 스니펫 저장소의 SSH URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

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",
  "imported": false,
  "imported_from": "none",
  "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>" \
  --url "https://gitlab.example.com/api/v4/snippets/1"

가능한 반환 코드:

코드 설명
204 삭제가 성공했습니다. 데이터가 반환되지 않습니다.
404 스니펫을 찾을 수 없습니다.

모든 공개 스니펫 목록 조회#

모든 공개 스니펫을 나열합니다.

GET /snippets/public

지원되는 속성:

속성 유형 필수 설명
created_after 날짜시간 아니오 주어진 시간 이후에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
created_before 날짜시간 아니오 주어진 시간 이전에 생성된 스니펫을 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 기대됩니다.
page 정수 아니오 조회할 페이지.
per_page 정수 아니오 페이지당 반환할 스니펫 수.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
file_name 문자열 스니펫 파일 이름.
id 정수 스니펫의 ID.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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에서 도입되었습니다.

현재 사용자가 접근할 수 있는 모든 스니펫을 나열합니다. Administrator 또는 Auditor 접근 수준의 사용자는 모든 스니펫(개인 및 프로젝트 모두)을 볼 수 있습니다.

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에서 도입되었습니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
author 객체 스니펫 작성자를 나타내는 사용자 객체.
created_at 문자열 스니펫이 생성된 날짜 및 시간.
description 문자열 스니펫에 대한 설명.
file_name 문자열 스니펫 파일 이름.
files 배열 스니펫 파일 배열.
id 정수 스니펫의 ID.
imported 불리언 true이면 스니펫이 가져온 것입니다.
imported_from 문자열 가져온 출처.
project_id 정수 연관된 프로젝트의 ID. 개인 스니펫의 경우 null.
raw_url 문자열 원시 스니펫 콘텐츠의 URL.
repository_storage 문자열 스니펫이 사용하는 저장소 스토리지.
title 문자열 스니펫의 제목.
updated_at 문자열 스니펫이 마지막으로 업데이트된 날짜 및 시간.
visibility 문자열 스니펫의 공개 범위 수준.
web_url 문자열 GitLab UI의 스니펫 URL.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/snippets/all?per_page=2&page=1"

응답 예시:

[
  {
    "id": 113,
    "title": "Internal Project Snippet",
    "description": null,
    "visibility": "internal",
    "imported": false,
    "imported_from": "none",
    "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": "Private Personal Snippet",
    "description": null,
    "visibility": "private",
    "imported": false,
    "imported_from": "none",
    "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": "Public Personal Snippet",
    "description": null,
    "visibility": "public",
    "imported": false,
    "imported_from": "none",
    "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"
  }
]

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

Note

관리자만 사용 가능합니다.

GET /snippets/:id/user_agent_detail

지원되는 속성:

속성 유형 필수 설명
id 정수 스니펫의 ID.

성공하면 200 OK와 다음 응답 속성을 반환합니다:

속성 유형 설명
akismet_submitted 불리언 true이면 세부 정보가 Akismet에 제출되었습니다.
ip_address 문자열 스니펫 생성에 사용된 IP 주소.
user_agent 문자열 스니펫 생성에 사용된 사용자 에이전트 문자열.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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
}