Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
60b3ea94
Commit
60b3ea94
authored
Feb 08, 2019
by
Evan Read
Committed by
Achilleas Pipinellis
Feb 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor snippets API documentation page
parent
e04ca9a6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
152 additions
and
71 deletions
+152
-71
doc/api/snippets.md
doc/api/snippets.md
+146
-70
doc/user/snippets.md
doc/user/snippets.md
+6
-1
No files found.
doc/api/snippets.md
View file @
60b3ea94
# Snippets API
# Snippets API
> [Introduced][ce-6373] in GitLab 8.15.
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6373) in GitLab 8.15.
Snippets API operates on
[
snippets
](
../user/snippets.md
)
.
## Snippet visibility level
## Snippet visibility level
Snippets in GitLab can be either private, internal, or public.
Snippets in GitLab can be either private, internal, or public.
You can set it with the
`visibility`
field in the snippet.
You can set it with the
`visibility`
field in the snippet.
Constant
s for snippet visibility levels are:
Valid value
s for snippet visibility levels are:
| Visibility | Description |
| Visibility | Description |
|
---------- | -----------
|
|
:-----------|:----------------------------------------------------
|
|
`private`
|
The snippet is visible only to the snippet creator
|
|
`private`
|
Snippet is visible only to the snippet creator.
|
|
`internal`
|
The snippet is visible for any logged in user
|
|
`internal`
|
Snippet is visible for any logged in user.
|
|
`public`
|
The snippet can be accessed without any authentication
|
|
`public`
|
Snippet can be accessed without any authentication.
|
## List
snippets
## List
all snippets for a user
Get a list of current user's snippets.
Get a list of
the
current user's snippets.
```
```
text
GET /snippets
GET /snippets
```
```
## Single snippet
Example request:
Get a single snippet.
```
sh
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets
```
Example response:
```
json
[
{
"id"
:
42
,
"title"
:
"Voluptatem iure ut qui aut et consequatur quaerat."
,
"file_name"
:
"mclaughlin.rb"
,
"description"
:
null
,
"visibility"
:
"internal"
,
"author"
:
{
"id"
:
22
,
"name"
:
"User 0"
,
"username"
:
"user0"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/52e4ce24a915fb7e51e1ad3b57f4b00a?s=80&d=identicon"
,
"web_url"
:
"http://localhost:3000/user0"
},
"updated_at"
:
"2018-09-18T01:12:26.383Z"
,
"created_at"
:
"2018-09-18T01:12:26.383Z"
,
"project_id"
:
null
,
"web_url"
:
"http://localhost:3000/snippets/42"
,
"raw_url"
:
"http://localhost:3000/snippets/42/raw"
},
{
"id"
:
41
,
"title"
:
"Ut praesentium non et atque."
,
"file_name"
:
"ondrickaemard.rb"
,
"description"
:
null
,
"visibility"
:
"internal"
,
"author"
:
{
"id"
:
22
,
"name"
:
"User 0"
,
"username"
:
"user0"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/52e4ce24a915fb7e51e1ad3b57f4b00a?s=80&d=identicon"
,
"web_url"
:
"http://localhost:3000/user0"
},
"updated_at"
:
"2018-09-18T01:12:26.360Z"
,
"created_at"
:
"2018-09-18T01:12:26.360Z"
,
"project_id"
:
null
,
"web_url"
:
"http://localhost:3000/snippets/41"
,
"raw_url"
:
"http://localhost:3000/snippets/41/raw"
}
]
```
```
## Get a single snippet
Get a single snippet.
```
text
GET /snippets/:id
GET /snippets/:id
```
```
Parameters:
Parameters:
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|:----------|:--------|:---------|:---------------------------|
|
`id`
| Integer | yes | The ID of a snippet |
|
`id`
| integer | yes | ID of snippet to retrieve. |
Example request:
```
ba
sh
```
sh
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/1
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/1
```
```
...
@@ -69,46 +126,52 @@ Example response:
...
@@ -69,46 +126,52 @@ Example response:
Get a single snippet's raw contents.
Get a single snippet's raw contents.
```
```
text
GET /snippets/:id/raw
GET /snippets/:id/raw
```
```
Parameters:
Parameters:
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|:----------|:--------|:---------|:---------------------------|
|
`id`
| Integer | yes | The ID of a snippet |
|
`id`
| integer | yes | ID of snippet to retrieve. |
Example request:
```
ba
sh
```
sh
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/1/raw
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/1/raw
```
```
Example response:
Example response:
```
```
text
Hello World snippet
Hello World snippet
```
```
## Create new snippet
## Create new snippet
Create
s a new snippet. The user must have permission to create new snippets
.
Create
a new snippet
.
```
NOTE:
**Note:**
The user must have permission to create new snippets.
```
text
POST /snippets
POST /snippets
```
```
Parameters:
Parameters:
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
|
--------- | ---- | -------- | -----------
|
|
:--------------|:-------|:---------|:---------------------------------------------------
|
|
`title`
| String | yes | The title of a snippet
|
|
`title`
| string | yes | Title of a snippet.
|
|
`file_name`
| String | yes | The name of a snippet file
|
|
`file_name`
| string | yes | Name of a snippet file.
|
|
`content`
| String | yes | The content of a snippet
|
|
`content`
| string | yes | Content of a snippet.
|
|
`description`
| String | no | The description of a snippet
|
|
`description`
| string | no | Description of a snippet.
|
|
`visibility`
| String | no | The snippet's visibility
|
|
`visibility`
| string | no | Snippet's
[
visibility
](
#snippet-visibility-level
)
.
|
Example request:
```
ba
sh
```
sh
curl
--request
POST
\
curl
--request
POST
\
--data
'{"title": "This is a snippet", "content": "Hello world", "description": "Hello World snippet", "file_name": "test.txt", "visibility": "internal" }'
\
--data
'{"title": "This is a snippet", "content": "Hello world", "description": "Hello World snippet", "file_name": "test.txt", "visibility": "internal" }'
\
--header
'Content-Type: application/json'
\
--header
'Content-Type: application/json'
\
...
@@ -142,25 +205,29 @@ Example response:
...
@@ -142,25 +205,29 @@ Example response:
## Update snippet
## Update snippet
Update
s an existing snippet. The user must have permission to change
an existing snippet.
Update an existing snippet.
```
NOTE:
**Note:**
The user must have permission to change an existing snippet.
```
text
PUT /snippets/:id
PUT /snippets/:id
```
```
Parameters:
Parameters:
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
|
--------- | ---- | -------- | -----------
|
|
:--------------|:--------|:---------|:---------------------------------------------------
|
|
`id`
| Integer | yes | The ID of a snippet
|
|
`id`
| integer | yes | ID of snippet to update.
|
|
`title`
| String | no | The title of a snippet
|
|
`title`
| string | no | Title of a snippet.
|
|
`file_name`
| String | no | The name of a snippet file
|
|
`file_name`
| string | no | Name of a snippet file.
|
|
`description`
| String | no | The description of a snippet
|
|
`description`
| string | no | Description of a snippet.
|
|
`content`
| String | no | The content of a snippet
|
|
`content`
| string | no | Content of a snippet.
|
|
`visibility`
| String | no | The snippet's visibility
|
|
`visibility`
| string | no | Snippet's
[
visibility
](
#snippet-visibility-level
)
.
|
Example request:
```
ba
sh
```
sh
curl
--request
PUT
\
curl
--request
PUT
\
--data
'{"title": "foo", "content": "bar"}'
\
--data
'{"title": "foo", "content": "bar"}'
\
--header
'Content-Type: application/json'
\
--header
'Content-Type: application/json'
\
...
@@ -194,38 +261,49 @@ Example response:
...
@@ -194,38 +261,49 @@ Example response:
## Delete snippet
## Delete snippet
Delete
s
an existing snippet.
Delete an existing snippet.
```
```
text
DELETE /snippets/:id
DELETE /snippets/:id
```
```
Parameters:
Parameters:
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
|
--------- | ---- | -------- | -----------
|
|
:----------|:--------|:---------|:-------------------------
|
|
`id`
| Integer | yes | The ID of a snippet
|
|
`id`
| integer | yes | ID of snippet to delete.
|
Example request:
```
```
sh
curl
--request
DELETE
--header
"PRIVATE-TOKEN: <your_access_token>"
"https://gitlab.example.com/api/v4/snippets/1"
curl
--request
DELETE
--header
"PRIVATE-TOKEN: <your_access_token>"
"https://gitlab.example.com/api/v4/snippets/1"
```
```
upon successful delete a
`204 No content`
HTTP code shall be expected, with no data,
The following are possible return codes:
but if the snippet is non-existent, a
`404 Not Found`
will be returned.
## Explore all public snippets
| Code | Description |
|:------|:--------------------------------------------|
|
`204`
| Delete was successful. No data is returned. |
|
`404`
| The snippet wasn't found. |
```
## List all public snippets
List all public snippets.
```
text
GET /snippets/public
GET /snippets/public
```
```
Parameters:
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
|
--------- | ---- | -------- | -----------
|
|
:-----------|:--------|:---------|:---------------------------------------
|
|
`per_page`
|
Integer | no | number of snippets to return per page
|
|
`per_page`
|
integer | no | Number of snippets to return per page.
|
|
`page`
|
Integer | no | the page to retrieve
|
|
`page`
|
integer | no | Page to retrieve.
|
```
bash
Example request:
```
sh
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/public?per_page
=
2&page
=
1
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/public?per_page
=
2&page
=
1
```
```
...
@@ -273,21 +351,22 @@ Example response:
...
@@ -273,21 +351,22 @@ Example response:
## Get user agent details
## Get user agent details
> **Notes:**
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12655) in GitLab 9.4.
> [Introduced][ce-29508] in GitLab 9.4.
Available only for admins.
NOTE:
**Note:**
Available only for administrators.
```
```
text
GET /snippets/:id/user_agent_detail
GET /snippets/:id/user_agent_detail
```
```
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
|
-------------|---------|----------|-----------------------
---------------|
|
:----------|:--------|:---------|:
---------------|
|
`id`
| Integer | yes | The ID of a snippet
|
|
`id`
| integer | yes | ID of snippet.
|
```
bash
Example request:
```
sh
curl
--request
GET
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/1/user_agent_detail
curl
--request
GET
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/snippets/1/user_agent_detail
```
```
...
@@ -300,6 +379,3 @@ Example response:
...
@@ -300,6 +379,3 @@ Example response:
"akismet_submitted"
:
false
"akismet_submitted"
:
false
}
}
```
```
[
ce-6373
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6373
[
ce-29508
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12655
doc/user/snippets.md
View file @
60b3ea94
...
@@ -4,7 +4,12 @@ With GitLab Snippets you can store and share bits of code and text with other us
...
@@ -4,7 +4,12 @@ With GitLab Snippets you can store and share bits of code and text with other us
![
GitLab Snippet
](
img/gitlab_snippet.png
)
![
GitLab Snippet
](
img/gitlab_snippet.png
)
There are 2 types of snippets, personal snippets and project snippets.
Snippets can be maintained using
[
snippets API
](
../api/snippets.md
)
.
There are two types of snippets:
-
Personal snippets.
-
Project snippets.
## Personal snippets
## Personal snippets
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment