1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
---
stage: Package
group: Package
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
---
# Composer API
This is the API documentation for [Composer Packages](../../user/packages/composer_repository/index.md).
WARNING:
This API is used by the [Composer package manager client](https://getcomposer.org/)
and is generally not meant for manual consumption.
For instructions on how to upload and install Composer packages from the GitLab
package registry, see the [Composer package registry documentation](../../user/packages/composer_repository/index.md).
NOTE:
These endpoints do not adhere to the standard API authentication methods.
See the [Composer package registry documentation](../../user/packages/composer_repository/index.md)
for details on which headers and token types are supported.
## Base repository request
Returns the repository URL templates for requesting individual packages:
```plaintext
GET group/:id/-/packages/composer/packages
```
| Attribute | Type | Required | Description |
| --------- | ------ | -------- | ----------- |
| `id` | string | yes | The ID or full path of the group. |
```shell
curl --user <username>:<personal_access_token> "https://gitlab.example.com/api/v4/group/1/-/packages/composer/packages"
```
Example response:
```json
{
"packages": [],
"metadata-url": "/api/v4/group/1/-/packages/composer/p2/%package%.json",
"provider-includes": {
"p/%hash%.json": {
"sha256": "082df4a5035f8725a12i4a3d2da5e6aaa966d06843d0a5c6d499313810427bd6"
}
},
"providers-url": "/api/v4/group/1/-/packages/composer/%package%$%hash%.json"
}
```
This endpoint is used by Composer V1 and V2. To see the V2-specific response, include the Composer
`User-Agent` header. Using Composer V2 is recommended over V1.
```shell
curl --user <username>:<personal_access_token> \
--header "User-Agent: Composer/2" \
"https://gitlab.example.com/api/v4/group/1/-/packages/composer/packages"
```
Example response:
```json
{
"packages": [],
"metadata-url": "/api/v4/group/1/-/packages/composer/p2/%package%.json"
}
```
## V1 packages list
Given the V1 provider SHA, returns a list of packages in the repository. Using Composer V2 is
recommended over V1.
```plaintext
GET group/:id/-/packages/composer/p/:sha
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | string | yes | The ID or full path of the group. |
| `sha` | string | yes | The provider SHA, provided by the Composer [base request](#base-repository-request). |
```shell
curl --user <username>:<personal_access_token> "https://gitlab.example.com/api/v4/group/1/-/packages/composer/p/082df4a5035f8725a12i4a3d2da5e6aaa966d06843d0a5c6d499313810427bd6"
```
Example response:
```json
{
"providers": {
"my-org/my-composer-package": {
"sha256": "5c873497cdaa82eda35af5de24b789be92dfb6510baf117c42f03899c166b6e7"
}
}
}
```
## V1 Package Metadata
Returns the list of versions and metadata for a given package. Using Composer V2 is recommended over
V1.
```plaintext
GET group/:id/-/packages/composer/:package_name$:sha
```
Note the `$` symbol in the URL. When making requests, you may need to use the URL-encoded version of
the symbol `%24` (see example below).
| Attribute | Type | Required | Description |
| -------------- | ------ | -------- | ----------- |
| `id` | string | yes | The ID or full path of the group. |
| `package_name` | string | yes | The name of the package. |
| `sha` | string | yes | The SHA digest of the package, provided by the [V1 packages list](#v1-packages-list). |
```shell
curl --user <username>:<personal_access_token> "https://gitlab.example.com/api/v4/group/1/-/packages/composer/my-org/my-composer-package%245c873497cdaa82eda35af5de24b789be92dfb6510baf117c42f03899c166b6e7"
```
Example response:
```json
{
"packages": {
"my-org/my-composer-package": {
"1.0.0": {
"name": "my-org/my-composer-package",
"type": "library",
"license": "GPL-3.0-only",
"version": "1.0.0",
"dist": {
"type": "zip",
"url": "https://gitlab.example.com/api/v4/projects/1/packages/composer/archives/my-org/my-composer-package.zip?sha=673594f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"reference": "673594f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"shasum": ""
},
"source": {
"type": "git",
"url": "https://gitlab.example.com/my-org/my-composer-package.git",
"reference": "673594f85a55fe3c0eb45df7bd2fa9d95a1601ab"
},
"uid": 1234567
},
"2.0.0": {
"name": "my-org/my-composer-package",
"type": "library",
"license": "GPL-3.0-only",
"version": "2.0.0",
"dist": {
"type": "zip",
"url": "https://gitlab.example.com/api/v4/projects/1/packages/composer/archives/my-org/my-composer-package.zip?sha=445394f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"reference": "445394f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"shasum": ""
},
"source": {
"type": "git",
"url": "https://gitlab.example.com/my-org/my-composer-package.git",
"reference": "445394f85a55fe3c0eb45df7bd2fa9d95a1601ab"
},
"uid": 1234567
}
}
}
}
```
## V2 Package Metadata
Returns the list of versions and metadata for a given package:
```plaintext
GET group/:id/-/packages/composer/p2/:package_name
```
| Attribute | Type | Required | Description |
| -------------- | ------ | -------- | ----------- |
| `id` | string | yes | The ID or full path of the group. |
| `package_name` | string | yes | The name of the package. |
```shell
curl --user <username>:<personal_access_token> "https://gitlab.example.com/api/v4/group/1/-/packages/composer/p2/my-org/my-composer-package"
```
Example response:
```json
{
"packages": {
"my-org/my-composer-package": {
"1.0.0": {
"name": "my-org/my-composer-package",
"type": "library",
"license": "GPL-3.0-only",
"version": "1.0.0",
"dist": {
"type": "zip",
"url": "https://gitlab.example.com/api/v4/projects/1/packages/composer/archives/my-org/my-composer-package.zip?sha=673594f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"reference": "673594f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"shasum": ""
},
"source": {
"type": "git",
"url": "https://gitlab.example.com/my-org/my-composer-package.git",
"reference": "673594f85a55fe3c0eb45df7bd2fa9d95a1601ab"
},
"uid": 1234567
},
"2.0.0": {
"name": "my-org/my-composer-package",
"type": "library",
"license": "GPL-3.0-only",
"version": "2.0.0",
"dist": {
"type": "zip",
"url": "https://gitlab.example.com/api/v4/projects/1/packages/composer/archives/my-org/my-composer-package.zip?sha=445394f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"reference": "445394f85a55fe3c0eb45df7bd2fa9d95a1601ab",
"shasum": ""
},
"source": {
"type": "git",
"url": "https://gitlab.example.com/my-org/my-composer-package.git",
"reference": "445394f85a55fe3c0eb45df7bd2fa9d95a1601ab"
},
"uid": 1234567
}
}
}
}
```
## Create a package
Create a Composer package from a Git tag or branch:
```plaintext
POST projects/:id/packages/composer
```
| Attribute | Type | Required | Description |
| --------- | ------ | -------- | ----------- |
| `id` | string | yes | The ID or full path of the group. |
| `tag` | string | no | The name of the tag to target for the package. |
| `branch` | string | no | The name of the branch to target for the package. |
```shell
curl --request POST --user <username>:<personal_access_token> \
--data tag=v1.0.0 "https://gitlab.example.com/api/v4/projects/1/packages/composer"
```
Example response:
```json
{
"message": "201 Created"
}
```
## Download a package archive
Download a Composer package. This URL is provided in the [v1](#v1-package-metadata)
or [v2 package metadata](#v2-package-metadata)
response. A `.zip` file extension must be in the request.
```plaintext
GET projects/:id/packages/composer/archives/:package_name
```
| Attribute | Type | Required | Description |
| -------------- | ------ | -------- | ----------- |
| `id` | string | yes | The ID or full path of the group. |
| `package_name` | string | yes | The name of the package. |
| `sha` | string | yes | The target SHA of the requested package version. |
```shell
curl --user <username>:<personal_access_token> "https://gitlab.example.com/api/v4/projects/1/packages/composer/archives/my-org/my-composer-package.zip?sha=673594f85a55fe3c0eb45df7bd2fa9d95a1601ab"
```
Write the output to file:
```shell
curl --user <username>:<personal_access_token> "https://gitlab.example.com/api/v4/projects/1/packages/composer/archives/my-org/my-composer-package.zip?sha=673594f85a55fe3c0eb45df7bd2fa9d95a1601ab" >> package.tar.gz
```
This writes the downloaded file to `package.tar.gz` in the current directory.
|