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 | ID or URL- |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of 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 | ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of a snippet.files.files,content must be provided |
description | String | Description of the snippet |
file_Required | String | The name of a snippet file |
files | Array of objects | Array of files for the snippet.content.files,content must be provided |
files[].Required | String | Content of the snippet file |
files[].Required | String | Path of the snippet file |
titleRequired | String | Title of the snippet |
visibilityRequired | String | Visibility level for the snippet.internal value is not availableAllowed 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 | ID or URL- |
snippet_Path, | Integer | ID of the 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 | ID or URL- |
snippet_Path, | Integer | ID of the snippet |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | Content of the snippet.files instead.files.content,description,files,file_,title,visibility must be provided |
description | String | Description of the snippet.content,description,files,file_,title,visibility must be provided |
file_ | String | Name of the snippet file.files instead.files.content,description,files,file_,title,visibility must be provided |
files | Array of objects | Array of files to update for the snippet.content,file_.content,description,files,file_,title,visibility must be provided |
files[].Required | String | The type of action to perform on the file, Allowed values: create,update,delete,moveMinimum length: 1 |
files[]. | String | Content of the snippet file |
files[]. | String | Path of the snippet file |
files[]. | String | Previous path of the snippet file |
title | String | Title of the snippet.content,description,files,file_,title,visibility must be provided |
visibility | String | Visibility level for the snippet.internal value is not available.content,description,files,file_,title,visibility must be providedAllowed 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 | ID or URL- |
snippet_Path, | Integer | ID of the 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 | ID or URL- |
refPath, | String | The name of branch, |
file_Path, | String | The URL- |
snippet_Path, | Integer | ID of the 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 | ID or URL- |
snippet_Path, | Integer | ID of the 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 | ID or URL- |
snippet_Path, | Integer | ID of the 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 on or after the specified time |
created_Query | String (date- | Return snippets created on or before the specified time |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of 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.files,content must be provided |
description | String | Description of the snippet |
file_Required | String | The name of a snippet file |
files | Array of objects | Array of files for the snippet.content.files,content must be provided |
files[].Required | String | Content of the snippet file |
files[].Required | String | Path of the snippet file |
titleRequired | String | Title of the snippet |
visibility | String | Visibility level for the snippet.internal value is not availableAllowed 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 on or after the specified time |
created_Query | String (date- | Return snippets created on or before the specified time |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of 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 on or after the specified time |
created_Query | String (date- | Return snippets created on or before the specified time |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of 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 | ID of the 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 | ID of the snippet |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of a snippet.files.content,description,files,file_,title,visibility must be provided |
description | String | Description of the snippet.content,description,files,file_,title,visibility must be provided |
file_ | String | The name of a snippet file.files.content,description,files,file_,title,visibility must be provided |
files | Array of objects | Array of files to update for the snippet.content,file_.content,description,files,file_,title,visibility must be provided |
files[].Required | String | The type of action to perform on the file, Allowed values: create,update,delete,moveMinimum length: 1 |
files[]. | String | Content of the snippet file |
files[]. | String | Path of the snippet file |
files[]. | String | Previous path of the snippet file |
title | String | Title of the snippet.content,description,files,file_,title,visibility must be provided |
visibility | String | Visibility level for the snippet.internal value is not available.content,description,files,file_,title,visibility must be providedAllowed 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 | ID of the 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 | ID of the 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 | ID of the 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 | ID of the 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: |