Use this API to manage personal and project snippets.
To move snippets between storages, use the snippet repository storage moves API.
List all snippets for a project
GET /api/v4/projects/{id}/snippets
Lists all snippets for a specified project.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Create a project snippet
POST /api/v4/projects/{id}/snippets
Creates a project snippet. The user must have permission to create snippets.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of a snippet.files |
description | String | The description of a snippet |
file_Required | String | The name of a snippet file |
files | Array of objects | An array of files.content |
files[].Required | String | The content of a snippet file |
files[].Required | String | The path of a snippet file |
titleRequired | String | The title of the snippet |
visibilityRequired | String | The visibility of the snippet Allowed values: private,internal,publicMinimum length: 1 |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Validation error | — |
404 | Not found | — |
422 | Unprocessable entity | — |
Retrieve a project snippet
GET /api/v4/projects/{id}/snippets/{snippet_id}
Retrieves a specified project snippet.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
snippet_Path, | Integer | The ID of a project snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Update a project snippet
PUT /api/v4/projects/{id}/snippets/{snippet_id}
Updates a specified project snippet. The user must have permission to modify snippets. Updates to snippets with multiple files must use the files attribute.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
snippet_Path, | Integer | The ID of a project snippet |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of the snippet.files |
description | String | The description of a snippet |
file_ | String | The file name of the snippet.files |
files | Array of objects | An array of files to update.content,file_ |
files[].Required | String | The type of action to perform on the file, Allowed values: create,update,delete,moveMinimum length: 1 |
files[]. | String | The content of a snippet |
files[]. | String | The file path of a snippet file |
files[]. | String | The previous path of a snippet file |
title | String | The title of the snippet |
visibility | String | The visibility of the snippet Allowed values: private,internal,public |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Validation error | — |
404 | Not found | — |
422 | Unprocessable entity | — |
Delete a project snippet
DELETE /api/v4/projects/{id}/snippets/{snippet_id}
Deletes a specified project snippet.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
snippet_Path, | Integer | The ID of a project snippet |
Responses
| Code | Description | Schema |
|---|---|---|
204 | No Content | — |
400 | Validation error | — |
404 | Not found | — |
Retrieve snippet repository file content
GET /api/v4/projects/{id}/snippets/{snippet_id}/files/{ref}/{file_path}/raw
Retrieves the raw file content from a snippet repository as plain text.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
refPath, | String | The name of branch, |
file_Path, | String | The URL- |
snippet_Path, | Integer | The ID of a project snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Retrieve a raw project snippet
GET /api/v4/projects/{id}/snippets/{snippet_id}/raw
Retrieves the raw contents of a specified project snippet as plain text
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
snippet_Path, | Integer | The ID of a project snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Retrieve user agent details for a project snippet
GET /api/v4/projects/{id}/snippets/{snippet_id}/user_agent_detail
Retrieves user agent details for a specified snippet. Available only for administrators.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- |
snippet_Path, | Integer | The ID of a project snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
List all snippets for current user
GET /api/v4/snippets
Lists all snippets for the currently authenticated user.
Parameters
| Name | Type | Description |
|---|---|---|
created_Query | String (date- | Return snippets created after the specified time |
created_Query | String (date- | Return snippets created before the specified time |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Create a snippet
POST /api/v4/snippets
Creates a snippet.
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of a snippet.files |
description | String | The description of a snippet |
file_Required | String | The name of a snippet file |
files | Array of objects | An array of files.content |
files[].Required | String | The content of a snippet file |
files[].Required | String | The path of a snippet file |
titleRequired | String | The title of a snippet |
visibility | String | The visibility of the snippet Allowed values: private,internal,publicDefault: internal |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | Validation error | — |
404 | Not found | — |
422 | Unprocessable entity | — |
List all snippets
GET /api/v4/snippets/all
Lists all snippets available to the currently authenticated user. Users with Administrator or Auditor access levels can see all snippets (both personal and project). This feature was introduced in GitLab 16.3.
Parameters
| Name | Type | Description |
|---|---|---|
created_Query | String (date- | Return snippets created after the specified time |
created_Query | String (date- | Return snippets created before the specified time |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
List all public snippets
GET /api/v4/snippets/public
Lists all public snippets accessible to the currently authenticated user.
Parameters
| Name | Type | Description |
|---|---|---|
created_Query | String (date- | Return snippets created after the specified time |
created_Query | String (date- | Return snippets created before the specified time |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Retrieve a snippet
GET /api/v4/snippets/{id}
Retrieves a specified snippet.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | The ID of a snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Update snippet
PUT /api/v4/snippets/{id}
Updates a specified snippet.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | The ID of a snippet |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of a snippet.files |
description | String | The description of a snippet |
file_ | String | The name of a snippet file.files |
files | Array of objects | An array of files to update.content,file_ |
files[].Required | String | The type of action to perform on the file, Allowed values: create,update,delete,moveMinimum length: 1 |
files[]. | String | The content of a snippet |
files[]. | String | The file path of a snippet file |
files[]. | String | The previous path of a snippet file |
title | String | The title of a snippet |
visibility | String | The visibility of the snippet Allowed values: private,internal,public |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Validation error | — |
404 | Not found | — |
422 | Unprocessable entity | — |
Delete snippet
DELETE /api/v4/snippets/{id}
Deletes a specified snippet.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | The ID of a snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Validation error | — |
404 | Not found | — |
Retrieve snippet file content
GET /api/v4/snippets/{id}/files/{ref}/{file_path}/raw
Retrieves the raw file content from a snippet as plain text.
Parameters
| Name | Type | Description |
|---|---|---|
refPath, | String | The name of branch, |
file_Path, | String | The URL- |
idPath, | String | The ID of a snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not found | — |
Retrieve a raw snippet
GET /api/v4/snippets/{id}/raw
Retrieves the raw contents of a specified snippet as plain text
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | The ID of a snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | — |
400 | Bad Request | — |
404 | Not found | — |
Retrieve user agent details for a snippet
GET /api/v4/snippets/{id}/user_agent_detail
Retrieves user agent details for a specified snippet.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | Integer | The ID of a snippet |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesCustomAttribute
| Property | Type | Description |
|---|---|---|
key | String | Example:foo |
value | String | Example:bar |
APIEntitiesPersonalSnippet
| Property | Type | Description |
|---|---|---|
author | APIEntities | — |
created_ | String (date- | Example:2012- |
description | String | Example:Ruby test snippet |
file_ | String | Example:add. |
files | Array of objects | Example:[{"path": |
http_ | String | Example:https: |
id | Integer (int64) | Example:1 |
imported | Boolean | Example:false |
imported_ | String | Example:none |
project_ | Integer (int64) | Example:1 |
raw_ | String | Example:http: |
ssh_ | String | Example:ssh: |
title | String | Example:test |
updated_ | String (date- | Example:2012- |
visibility | String | Example:public |
web_ | String | Example:http: |
APIEntitiesProjectSnippet
| Property | Type | Description |
|---|---|---|
author | APIEntities | — |
created_ | String (date- | Example:2012- |
description | String | Example:Ruby test snippet |
file_ | String | Example:add. |
files | Array of objects | Example:[{"path": |
http_ | String | Example:https: |
id | Integer (int64) | Example:1 |
imported | Boolean | Example:false |
imported_ | String | Example:none |
project_ | Integer (int64) | Example:1 |
raw_ | String | Example:http: |
ssh_ | String | Example:ssh: |
title | String | Example:test |
updated_ | String (date- | Example:2012- |
visibility | String | Example:public |
web_ | String | Example:http: |
APIEntitiesSnippet
| Property | Type | Description |
|---|---|---|
author | APIEntities | — |
created_ | String (date- | Example:2012- |
description | String | Example:Ruby test snippet |
file_ | String | Example:add. |
files | Array of objects | Example:[{"path": |
http_ | String | Example:https: |
id | Integer (int64) | Example:1 |
imported | Boolean | Example:false |
imported_ | String | Example:none |
project_ | Integer (int64) | Example:1 |
raw_ | String | Example:http: |
ssh_ | String | Example:ssh: |
title | String | Example:test |
updated_ | String (date- | Example:2012- |
visibility | String | Example:public |
web_ | String | Example:http: |
APIEntitiesUserAgentDetail
| Property | Type | Description |
|---|---|---|
akismet_ | Boolean | Example:false |
ip_ | String | Example:127. |
user_ | String | Example:Apple |
APIEntitiesUserBasic
| Property | Type | Description |
|---|---|---|
avatar_ | String | Example:/ |
avatar_ | String | Example:https: |
custom_ | Array of APIEntities | — |
id | Integer (int64) | Example:1 |
locked | Boolean | — |
name | String | Example:Administrator |
public_ | String | Example:john@example. |
state | String | Example:active |
username | String | Example:admin |
web_ | String | Example:https: |