---
title: "Create a project snippet"
method: POST
path: "/api/v4/projects/{id}/snippets"
tags: ["snippets"]
---

# Create a project snippet

`POST /api/v4/projects/{id}/snippets`

## Request

- Base URL: `https://gitlab.com`
- URL: `https://gitlab.com/api/v4/projects/{id}/snippets`
- Auth: none declared

Creates a project snippet. The user must have permission to create snippets.

## Path parameters

- `id` string, required

## Request body

- PostApiV4ProjectsIdSnippets: Create a project snippet
  - `title` string, required: The title of the snippet
  - `description` string: The description of a snippet
  - `visibility` 'private' | 'internal' | 'public', required: The visibility of the snippet
  - `files` object[]: An array of files
    - `file_path` string, required: The path of a snippet file
    - `content` string, required: The content of a snippet file
  - `content` string: The content of a snippet
  - `file_name` string, required: The name of a snippet file

## Response `201`

Create a project snippet

- APIEntitiesProjectSnippet: API_Entities_ProjectSnippet model
  - `id` integer, required
  - `title` string, required
  - `description` string, required
  - `visibility` string, required
  - `author` APIEntitiesUserBasic, required: API_Entities_UserBasic model
    - `id` integer, required
    - `username` string, required
    - `public_email` string, required
    - `name` string, required
    - `state` string, required
    - `locked` boolean, required
    - `avatar_url` string, required
    - `avatar_path` string
    - `custom_attributes` APIEntitiesCustomAttribute[]
      - `key` string, required
      - `value` string, required
    - `web_url` string, required
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required
  - `project_id` integer, required
  - `web_url` string, required
  - `raw_url` string, required
  - `ssh_url_to_repo` string
  - `http_url_to_repo` string
  - `file_name` string, required
  - `files` object[], required
  - `imported` boolean, required
  - `imported_from` string, required
  - `repository_storage` string

## Other responses

- `400`: Validation error
- `404`: Not found
- `422`: Unprocessable entity

---

[API](https://skmtc.dev/gitlab/apis/gitlab-api.md) - [All operations](https://skmtc.dev/gitlab/apis/gitlab-api/llms.txt) - [OpenAPI document](https://skmtc.dev/gitlab/apis/gitlab-api/revisions/b234947ef3f2?raw)
