Skip to content

Commit 34adee0

Browse files
committed
Extend docs for retrieving the package metadata
1 parent 93e8608 commit 34adee0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/api/package-metadata.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
To read the package metadata via API, use the Composer API on your Private Packagist repository.
44

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+
58
Read more about the API: https://packagist.org/apidoc#get-package-data
69

10+
711
### Example implementation
812

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+
919
```bash
1020
# Make sure the composer/metadata-minifer package is installed:
1121
composer require composer/metadata-minifier
@@ -22,6 +32,8 @@ $package = 'acme/package';
2232
// You can create a token in your Organization settings > Authentication Tokens
2333
$token = 'packagist_ort_..........';
2434

35+
// The p2/$vendor/$package.json endpoint contains only tagged releases. If you want to fetch information about branches (i.e. dev versions)
36+
// you need to use p2/$vendor/$package~dev.json.
2537
$apiUrl = sprintf('https://repo.packagist.com/%s/p2/%s.json', $organization, $package);
2638

2739
$ch = curl_init($apiUrl);

0 commit comments

Comments
 (0)