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. Creating snippets has a rate limit of 300 requests every hour for each authenticated user. The limit is shared between this endpoint, the endpoint that creates a personal snippet, and the createSnippet GraphQL mutation.
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 instead.files.files,content must be provided |
description | String | Description of the snippet |
file_Required | String | The name of a snippet file.files instead |
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. The user must have permission to create snippets. Creating snippets is rate limited to 300 requests every hour for each authenticated user. The limit is shared between this endpoint, creating a project snippet, and the createSnippet GraphQL mutation.
Request body (application/json)
| Property | Type | Description |
|---|---|---|
content | String | The content of a snippet.files instead.files.files,content must be provided |
description | String | Description of the snippet |
file_Required | String | The name of a snippet file.files instead |
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. The user must have permission to change the 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 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 | The name of a 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 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. Available only for administrators.
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 | Author of the snippet |
created_ | String (date- | Date and time when the snippet was created Example: 2012- |
description | String | Description of the snippet Example: Ruby test snippet |
file_ | String | Name of the snippet file Example: add. |
files | Array of objects | Array of snippet files Example: [{"path": |
http_ | String | HTTP URL to the snippet repository. Example: https: |
id | Integer (int64) | ID of the snippet Example: 1 |
imported | Boolean | If true,Example: false |
imported_ | String | Source of the import Example: none |
project_ | Integer (int64) | ID of the project the snippet belongs to.null for personal snippetsExample: 1 |
raw_ | String | URL to the raw snippet content Example: http: |
ssh_ | String | SSH URL to the snippet repository. Example: ssh: |
title | String | Title of the snippet Example: test |
updated_ | String (date- | Date and time when the snippet was last updated Example: 2012- |
visibility | String | Visibility level of the snippet Example: public |
web_ | String | URL to the snippet in the Git Example: http: |
APIEntitiesProjectSnippet
| Property | Type | Description |
|---|---|---|
author | APIEntities | Author of the snippet |
created_ | String (date- | Date and time when the snippet was created Example: 2012- |
description | String | Description of the snippet Example: Ruby test snippet |
file_ | String | Name of the snippet file Example: add. |
files | Array of objects | Array of snippet files Example: [{"path": |
http_ | String | HTTP URL to the snippet repository. Example: https: |
id | Integer (int64) | ID of the snippet Example: 1 |
imported | Boolean | If true,Example: false |
imported_ | String | Source of the import Example: none |
project_ | Integer (int64) | ID of the project the snippet belongs to.null for personal snippetsExample: 1 |
raw_ | String | URL to the raw snippet content Example: http: |
ssh_ | String | SSH URL to the snippet repository. Example: ssh: |
title | String | Title of the snippet Example: test |
updated_ | String (date- | Date and time when the snippet was last updated Example: 2012- |
visibility | String | Visibility level of the snippet Example: public |
web_ | String | URL to the snippet in the Git Example: http: |
APIEntitiesSnippet
| Property | Type | Description |
|---|---|---|
author | APIEntities | Author of the snippet |
created_ | String (date- | Date and time when the snippet was created Example: 2012- |
description | String | Description of the snippet Example: Ruby test snippet |
file_ | String | Name of the snippet file Example: add. |
files | Array of objects | Array of snippet files Example: [{"path": |
http_ | String | HTTP URL to the snippet repository. Example: https: |
id | Integer (int64) | ID of the snippet Example: 1 |
imported | Boolean | If true,Example: false |
imported_ | String | Source of the import Example: none |
project_ | Integer (int64) | ID of the project the snippet belongs to.null for personal snippetsExample: 1 |
raw_ | String | URL to the raw snippet content Example: http: |
ssh_ | String | SSH URL to the snippet repository. Example: ssh: |
title | String | Title of the snippet Example: test |
updated_ | String (date- | Date and time when the snippet was last updated Example: 2012- |
visibility | String | Visibility level of the snippet Example: public |
web_ | String | URL to the snippet in the Git Example: http: |
APIEntitiesUserAgentDetail
| Property | Type | Description |
|---|---|---|
akismet_ | Boolean | If true,Example: false |
ip_ | String | IP address of the client that created the item Example: 127. |
user_ | String | User agent string of the client that created the item Example: Apple |
APIEntitiesUserBasic
| Property | Type | Description |
|---|---|---|
avatar_ | String | Example:/ |
avatar_ | String | URL of the user’s avatar Example: https: |
custom_ | Array of APIEntities | — |
id | Integer (int64) | ID of the user Example: 1 |
locked | Boolean | If true, |
name | String | Name of the user.**** if the current user cannot read the bot’s project or groupExample: Administrator |
public_ | String | Public email address of the user Example: john@example. |
state | String | State of the user account.active,blocked,ldap_,blocked_,banned,deactivatedExample: active |
username | String | Username of the user Example: admin |
web_ | String | URL of the user’s profile Example: https: |