You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/package-metadata.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,20 @@
2
2
3
3
To read the package metadata via API, use the Composer API on your Private Packagist repository.
4
4
5
+
This is useful when you need to programmatically access package metadata beyond what's available through the Private Packagist API
6
+
(for example to read custom configuration from the `extra` section of a package's composer.json).
7
+
5
8
Read more about the API: https://packagist.org/apidoc#get-package-data
6
9
10
+
7
11
### Example implementation
8
12
13
+
The process works as follows:
14
+
1. Get the JSON from `https://repo.packagist.com/<org>/p2/<package>.json`
15
+
2. Authenticate using username `token` and an Authentication Token as password
16
+
3. Decode the JSON as nested arrays
17
+
4. Use [MetadataMinifier](https://github.com/composer/metadata-minifier) to expand the metadata for each package version: `$metadata = MetadataMinifier::expand($data['packages'][$package])`
18
+
9
19
```bash
10
20
# Make sure the composer/metadata-minifer package is installed:
11
21
composer require composer/metadata-minifier
@@ -22,6 +32,8 @@ $package = 'acme/package';
22
32
// You can create a token in your Organization settings > Authentication Tokens
23
33
$token = 'packagist_ort_..........';
24
34
35
+
// The p2/$vendor/$package.json endpoint contains only tagged releases. If you want to fetch information about branches (i.e. dev versions)
0 commit comments