2020-10-26 21:08:22 +00:00
---
2021-04-23 15:09:37 +00:00
stage: Manage
2021-12-23 15:11:20 +00:00
group: Authentication & Authorization
2020-11-26 06:09:20 +00:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-26 21:08:22 +00:00
---
2021-09-15 15:10:13 +00:00
# Group badges API **(FREE)**
2018-03-05 17:51:40 +00:00
2020-03-24 03:09:28 +00:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/17082) in GitLab 10.6.
2018-04-08 11:39:35 +00:00
2018-03-05 17:51:40 +00:00
## Placeholder tokens
2020-11-19 21:09:07 +00:00
Badges support placeholders that are replaced in real time in both the link and image URL. The allowed placeholders are:
2018-03-05 17:51:40 +00:00
2021-01-29 18:09:17 +00:00
<!-- vale gitlab.Spelling = NO -->
2020-11-19 21:09:07 +00:00
- **%{project_path}**: replaced by the project path.
- **%{project_id}**: replaced by the project ID.
- **%{default_branch}**: replaced by the project default branch.
- **%{commit_sha}**: replaced by the last project's commit SHA.
2018-03-05 17:51:40 +00:00
2021-01-29 18:09:17 +00:00
<!-- vale gitlab.Spelling = YES -->
2020-11-19 21:09:07 +00:00
Because these endpoints aren't inside a project's context, the information used to replace the placeholders comes
from the first group's project by creation date. If the group hasn't got any project the original URL with the placeholders is returned.
2018-03-05 17:51:40 +00:00
## List all badges of a group
Gets a list of a group's badges.
2020-02-27 09:09:01 +00:00
```plaintext
2018-03-05 17:51:40 +00:00
GET /groups/:id/badges
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2019-11-22 09:06:20 +00:00
| `name` | string | no | Name of the badges to return (case-sensitive). |
2018-03-05 17:51:40 +00:00
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/groups/:id/badges?name=Coverage"
2018-03-05 17:51:40 +00:00
```
Example response:
```json
[
{
2019-11-22 09:06:20 +00:00
"name": "Coverage",
2018-03-05 17:51:40 +00:00
"id": 1,
"link_url": "http://example.com/ci_status.svg?project=%{project_path}& ref=%{default_branch}",
"image_url": "https://shields.io/my/badge",
"rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project& ref=master",
"rendered_image_url": "https://shields.io/my/badge",
"kind": "group"
2019-11-22 09:06:20 +00:00
}
2018-03-05 17:51:40 +00:00
]
```
## Get a badge of a group
Gets a badge of a group.
2020-02-27 09:09:01 +00:00
```plaintext
2018-03-05 17:51:40 +00:00
GET /groups/:id/badges/:badge_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2018-03-05 17:51:40 +00:00
| `badge_id` | integer | yes | The badge ID |
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/groups/:id/badges/:badge_id"
2018-03-05 17:51:40 +00:00
```
Example response:
```json
{
"id": 1,
"link_url": "http://example.com/ci_status.svg?project=%{project_path}& ref=%{default_branch}",
"image_url": "https://shields.io/my/badge",
"rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project& ref=master",
"rendered_image_url": "https://shields.io/my/badge",
"kind": "group"
}
```
## Add a badge to a group
Adds a badge to a group.
2020-02-27 09:09:01 +00:00
```plaintext
2018-03-05 17:51:40 +00:00
POST /groups/:id/badges
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2018-03-05 17:51:40 +00:00
| `link_url` | string | yes | URL of the badge link |
| `image_url` | string | yes | URL of the badge image |
2020-01-30 15:09:15 +00:00
```shell
2021-06-02 15:09:59 +00:00
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " \
--data "link_url=https://gitlab.com/gitlab-org/gitlab-foss/commits/master& image_url=https://shields.io/my/badge1& position=0" \
"https://gitlab.example.com/api/v4/groups/:id/badges"
2018-03-05 17:51:40 +00:00
```
Example response:
```json
{
"id": 1,
2019-09-18 14:02:45 +00:00
"link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-05 17:51:40 +00:00
"image_url": "https://shields.io/my/badge1",
2019-09-18 14:02:45 +00:00
"rendered_link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-05 17:51:40 +00:00
"rendered_image_url": "https://shields.io/my/badge1",
"kind": "group"
}
```
## Edit a badge of a group
Updates a badge of a group.
2020-02-27 09:09:01 +00:00
```plaintext
2018-03-05 17:51:40 +00:00
PUT /groups/:id/badges/:badge_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2018-03-05 17:51:40 +00:00
| `badge_id` | integer | yes | The badge ID |
| `link_url` | string | no | URL of the badge link |
| `image_url` | string | no | URL of the badge image |
2020-01-30 15:09:15 +00:00
```shell
2021-06-02 15:09:59 +00:00
curl --request PUT --header "PRIVATE-TOKEN: < your_access_token > " \
"https://gitlab.example.com/api/v4/groups/:id/badges/:badge_id"
2018-03-05 17:51:40 +00:00
```
Example response:
```json
{
"id": 1,
2019-09-18 14:02:45 +00:00
"link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-05 17:51:40 +00:00
"image_url": "https://shields.io/my/badge",
2019-09-18 14:02:45 +00:00
"rendered_link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-05 17:51:40 +00:00
"rendered_image_url": "https://shields.io/my/badge",
"kind": "group"
}
```
## Remove a badge from a group
Removes a badge from a group.
2020-02-27 09:09:01 +00:00
```plaintext
2018-03-05 17:51:40 +00:00
DELETE /groups/:id/badges/:badge_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2018-03-05 17:51:40 +00:00
| `badge_id` | integer | yes | The badge ID |
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl --request DELETE --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/groups/:id/badges/:badge_id"
2018-03-05 17:51:40 +00:00
```
## Preview a badge from a group
Returns how the `link_url` and `image_url` final URLs would be after resolving the placeholder interpolation.
2020-02-27 09:09:01 +00:00
```plaintext
2018-03-05 17:51:40 +00:00
GET /groups/:id/badges/render
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the group ](index.md#namespaced-path-encoding ) owned by the authenticated user |
2018-03-05 17:51:40 +00:00
| `link_url` | string | yes | URL of the badge link|
| `image_url` | string | yes | URL of the badge image |
2020-01-30 15:09:15 +00:00
```shell
2020-05-28 00:08:37 +00:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/groups/:id/badges/render?link_url=http%3A%2F%2Fexample.com%2Fci_status.svg%3Fproject%3D%25%7Bproject_path%7D%26ref%3D%25%7Bdefault_branch%7D& image_url=https%3A%2F%2Fshields.io%2Fmy%2Fbadge"
2018-03-05 17:51:40 +00:00
```
Example response:
```json
2018-04-08 11:39:35 +00:00
{
2018-03-05 17:51:40 +00:00
"link_url": "http://example.com/ci_status.svg?project=%{project_path}& ref=%{default_branch}",
"image_url": "https://shields.io/my/badge",
"rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project& ref=master",
2021-04-29 12:09:58 +00:00
"rendered_image_url": "https://shields.io/my/badge"
2018-03-05 17:51:40 +00:00
}
```