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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesProjectSnippet
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project

Request body (application/json)

PropertyTypeDescription
contentStringThe content of a snippet. Deprecated. Use files instead. Mutually exclusive with files. Exactly one of files, content must be provided
descriptionStringDescription of the snippet
file_name
Required
StringThe name of a snippet file. Deprecated. Use files instead
filesArray of objectsArray of files for the snippet. Mutually exclusive with content. Exactly one of files, content must be provided
files[].content
Required
StringContent of the snippet file
files[].file_path
Required
StringPath of the snippet file
title
Required
StringTitle of the snippet
visibility
Required
StringVisibility level for the snippet. On GitLab.com, the internal value is not available
Allowed values: private, internal, public
Minimum length: 1

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesProjectSnippet
400Validation error—
404Not found—
422Unprocessable entity—

Retrieve a project snippet

GET /api/v4/projects/{id}/snippets/{snippet_id}

Retrieves a specified project snippet.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
snippet_id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesProjectSnippet
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
snippet_id
Path, required
IntegerID of the snippet

Request body (application/json)

PropertyTypeDescription
contentStringContent of the snippet. Deprecated. Use files instead. Mutually exclusive with files. At least one of content, description, files, file_name, title, visibility must be provided
descriptionStringDescription of the snippet. At least one of content, description, files, file_name, title, visibility must be provided
file_nameStringName of the snippet file. Deprecated. Use files instead. Mutually exclusive with files. At least one of content, description, files, file_name, title, visibility must be provided
filesArray of objectsArray of files to update for the snippet. Required when the snippet has multiple files. Mutually exclusive with content, file_name. At least one of content, description, files, file_name, title, visibility must be provided
files[].action
Required
StringThe type of action to perform on the file, must be one of: create, update, delete, move
Allowed values: create, update, delete, move
Minimum length: 1
files[].contentStringContent of the snippet file
files[].file_pathStringPath of the snippet file
files[].previous_pathStringPrevious path of the snippet file
titleStringTitle of the snippet. At least one of content, description, files, file_name, title, visibility must be provided
visibilityStringVisibility level for the snippet. On GitLab.com, the internal value is not available. At least one of content, description, files, file_name, title, visibility must be provided
Allowed values: private, internal, public

Responses

CodeDescriptionSchema
200OKAPIEntitiesProjectSnippet
400Validation error—
404Not found—
422Unprocessable entity—

Delete a project snippet

DELETE /api/v4/projects/{id}/snippets/{snippet_id}

Deletes a specified project snippet.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
snippet_id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
204No Content—
400Validation error—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
ref
Path, required
StringThe name of branch, tag or commit
file_path
Path, required
StringThe URL-encoded path to the file, like lib%2Fclass%2Erb
snippet_id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesProjectSnippet
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
snippet_id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesProjectSnippet
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
snippet_id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesUserAgentDetail
400Bad Request—
404Not found—

List all snippets for current user

GET /api/v4/snippets

Lists all snippets for the currently authenticated user.

Parameters

NameTypeDescription
created_after
Query
String (date-time)Return snippets created on or after the specified time
created_before
Query
String (date-time)Return snippets created on or before the specified time
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesSnippet
400Bad Request—
404Not 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)

PropertyTypeDescription
contentStringThe content of a snippet. Deprecated. Use files instead. Mutually exclusive with files. Exactly one of files, content must be provided
descriptionStringDescription of the snippet
file_name
Required
StringThe name of a snippet file. Deprecated. Use files instead
filesArray of objectsArray of files for the snippet. Mutually exclusive with content. Exactly one of files, content must be provided
files[].content
Required
StringContent of the snippet file
files[].file_path
Required
StringPath of the snippet file
title
Required
StringTitle of the snippet
visibilityStringVisibility level for the snippet. On GitLab.com, the internal value is not available
Allowed values: private, internal, public
Default: internal

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalSnippet
400Validation error—
404Not found—
422Unprocessable 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

NameTypeDescription
created_after
Query
String (date-time)Return snippets created on or after the specified time
created_before
Query
String (date-time)Return snippets created on or before the specified time
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesSnippet
400Bad Request—
404Not found—

List all public snippets

GET /api/v4/snippets/public

Lists all public snippets accessible to the currently authenticated user.

Parameters

NameTypeDescription
created_after
Query
String (date-time)Return snippets created on or after the specified time
created_before
Query
String (date-time)Return snippets created on or before the specified time
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesPersonalSnippet
400Bad Request—
404Not found—

Retrieve a snippet

GET /api/v4/snippets/{id}

Retrieves a specified snippet.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesPersonalSnippet
400Bad Request—
404Not found—

Update snippet

PUT /api/v4/snippets/{id}

Updates a specified snippet. The user must have permission to change the snippet.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the snippet

Request body (application/json)

PropertyTypeDescription
contentStringThe content of a snippet. Deprecated. Use files instead. Mutually exclusive with files. At least one of content, description, files, file_name, title, visibility must be provided
descriptionStringDescription of the snippet. At least one of content, description, files, file_name, title, visibility must be provided
file_nameStringThe name of a snippet file. Deprecated. Use files instead. Mutually exclusive with files. At least one of content, description, files, file_name, title, visibility must be provided
filesArray of objectsArray of files to update for the snippet. Required when the snippet has multiple files. Mutually exclusive with content, file_name. At least one of content, description, files, file_name, title, visibility must be provided
files[].action
Required
StringThe type of action to perform on the file, must be one of: create, update, delete, move
Allowed values: create, update, delete, move
Minimum length: 1
files[].contentStringContent of the snippet file
files[].file_pathStringPath of the snippet file
files[].previous_pathStringPrevious path of the snippet file
titleStringTitle of the snippet. At least one of content, description, files, file_name, title, visibility must be provided
visibilityStringVisibility level for the snippet. On GitLab.com, the internal value is not available. At least one of content, description, files, file_name, title, visibility must be provided
Allowed values: private, internal, public

Responses

CodeDescriptionSchema
200OKAPIEntitiesPersonalSnippet
400Validation error—
404Not found—
422Unprocessable entity—

Delete snippet

DELETE /api/v4/snippets/{id}

Deletes a specified snippet.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesPersonalSnippet
400Validation error—
404Not 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

NameTypeDescription
ref
Path, required
StringThe name of branch, tag or commit
file_path
Path, required
StringThe URL-encoded path to the file, like lib%2Fclass%2Erb
id
Path, required
StringID of the snippet

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not found—

Retrieve a raw snippet

GET /api/v4/snippets/{id}/raw

Retrieves the raw contents of a specified snippet as plain text

Parameters

NameTypeDescription
id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OK—
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
IntegerID of the snippet

Responses

CodeDescriptionSchema
200OKAPIEntitiesUserAgentDetail
400Bad Request—
404Not found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesCustomAttribute

PropertyTypeDescription
keyStringExample: foo
valueStringExample: bar

APIEntitiesPersonalSnippet

PropertyTypeDescription
authorAPIEntitiesUserBasicAuthor of the snippet
created_atString (date-time)Date and time when the snippet was created
Example: 2012-06-28T10:52:04Z
descriptionStringDescription of the snippet
Example: Ruby test snippet
file_nameStringName of the snippet file
Example: add.rb
filesArray of objectsArray of snippet files
Example: [{"path":"file.txt","raw_url":"https://gitlab.example.com/.../raw"}]
http_url_to_repoStringHTTP URL to the snippet repository. Returned only if the snippet repository exists
Example: https://gitlab.example.com/snippets/65.git
idInteger (int64)ID of the snippet
Example: 1
importedBooleanIf true, the snippet was imported
Example: false
imported_fromStringSource of the import
Example: none
project_idInteger (int64)ID of the project the snippet belongs to. null for personal snippets
Example: 1
raw_urlStringURL to the raw snippet content
Example: http://example.com/example/example/snippets/1/raw
ssh_url_to_repoStringSSH URL to the snippet repository. Returned only if the snippet repository exists
Example: ssh://user@gitlab.example.com/snippets/65.git
titleStringTitle of the snippet
Example: test
updated_atString (date-time)Date and time when the snippet was last updated
Example: 2012-06-28T10:52:04Z
visibilityStringVisibility level of the snippet
Example: public
web_urlStringURL to the snippet in the GitLab UI
Example: http://example.com/example/example/snippets/1

APIEntitiesProjectSnippet

PropertyTypeDescription
authorAPIEntitiesUserBasicAuthor of the snippet
created_atString (date-time)Date and time when the snippet was created
Example: 2012-06-28T10:52:04Z
descriptionStringDescription of the snippet
Example: Ruby test snippet
file_nameStringName of the snippet file
Example: add.rb
filesArray of objectsArray of snippet files
Example: [{"path":"file.txt","raw_url":"https://gitlab.example.com/.../raw"}]
http_url_to_repoStringHTTP URL to the snippet repository. Returned only if the snippet repository exists
Example: https://gitlab.example.com/snippets/65.git
idInteger (int64)ID of the snippet
Example: 1
importedBooleanIf true, the snippet was imported
Example: false
imported_fromStringSource of the import
Example: none
project_idInteger (int64)ID of the project the snippet belongs to. null for personal snippets
Example: 1
raw_urlStringURL to the raw snippet content
Example: http://example.com/example/example/snippets/1/raw
ssh_url_to_repoStringSSH URL to the snippet repository. Returned only if the snippet repository exists
Example: ssh://user@gitlab.example.com/snippets/65.git
titleStringTitle of the snippet
Example: test
updated_atString (date-time)Date and time when the snippet was last updated
Example: 2012-06-28T10:52:04Z
visibilityStringVisibility level of the snippet
Example: public
web_urlStringURL to the snippet in the GitLab UI
Example: http://example.com/example/example/snippets/1

APIEntitiesSnippet

PropertyTypeDescription
authorAPIEntitiesUserBasicAuthor of the snippet
created_atString (date-time)Date and time when the snippet was created
Example: 2012-06-28T10:52:04Z
descriptionStringDescription of the snippet
Example: Ruby test snippet
file_nameStringName of the snippet file
Example: add.rb
filesArray of objectsArray of snippet files
Example: [{"path":"file.txt","raw_url":"https://gitlab.example.com/.../raw"}]
http_url_to_repoStringHTTP URL to the snippet repository. Returned only if the snippet repository exists
Example: https://gitlab.example.com/snippets/65.git
idInteger (int64)ID of the snippet
Example: 1
importedBooleanIf true, the snippet was imported
Example: false
imported_fromStringSource of the import
Example: none
project_idInteger (int64)ID of the project the snippet belongs to. null for personal snippets
Example: 1
raw_urlStringURL to the raw snippet content
Example: http://example.com/example/example/snippets/1/raw
ssh_url_to_repoStringSSH URL to the snippet repository. Returned only if the snippet repository exists
Example: ssh://user@gitlab.example.com/snippets/65.git
titleStringTitle of the snippet
Example: test
updated_atString (date-time)Date and time when the snippet was last updated
Example: 2012-06-28T10:52:04Z
visibilityStringVisibility level of the snippet
Example: public
web_urlStringURL to the snippet in the GitLab UI
Example: http://example.com/example/example/snippets/1

APIEntitiesUserAgentDetail

PropertyTypeDescription
akismet_submittedBooleanIf true, the details were submitted to Akismet for spam detection
Example: false
ip_addressStringIP address of the client that created the item
Example: 127.0.0.1
user_agentStringUser agent string of the client that created the item
Example: AppleWebKit/537.36

APIEntitiesUserBasic

PropertyTypeDescription
avatar_pathStringExample: /user/avatar/28/The-Big-Lebowski-400-400.png
avatar_urlStringURL of the user’s avatar
Example: https://gravatar.com/avatar/1
custom_attributesArray of APIEntitiesCustomAttribute—
idInteger (int64)ID of the user
Example: 1
lockedBooleanIf true, the user account is locked, and the user cannot sign in until the lock expires or an administrator unlocks the account
nameStringName of the user. For a bot user, **** if the current user cannot read the bot’s project or group
Example: Administrator
public_emailStringPublic email address of the user
Example: john@example.com
stateStringState of the user account. Possible values: active, blocked, ldap_blocked, blocked_pending_approval, banned, or deactivated
Example: active
usernameStringUsername of the user
Example: admin
web_urlStringURL of the user’s profile
Example: https://gitlab.example.com/root