Skip to content

Commit 797a72c

Browse files
authored
Create api_v3_usage.rst in docs/source
Issue #1943
1 parent 00e9f24 commit 797a72c

File tree

1 file changed

+254
-0
lines changed

1 file changed

+254
-0
lines changed

docs/source/api_v3_usage.rst

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
Package Endpoint
2+
================
3+
4+
We are migrating from **API v1** to **API v3**.
5+
6+
Previously, the ``/api/packages`` endpoint exposed multiple routes:
7+
8+
- ``bulk_search``
9+
- ``bulk_lookup``
10+
- ``lookup``
11+
- ``all``
12+
13+
In **API v3**, all these capabilities are consolidated into a **single endpoint**:
14+
15+
::
16+
17+
POST /api/v3/packages
18+
19+
20+
Pagination
21+
----------
22+
23+
Responses from the package endpoint are **always paginated**, with **10 results per page**.
24+
25+
Each response includes:
26+
27+
- ``count`` — total number of results
28+
- ``next`` — URL for the next page
29+
- ``previous`` — URL for the previous page
30+
31+
If a package is associated with **more than 100 advisories**, the response will include:
32+
33+
- ``affected_by_vulnerabilities_url`` instead of ``affected_by_vulnerabilities``
34+
- ``fixing_vulnerabilities_url`` instead of ``fixing_vulnerabilities``
35+
36+
37+
Getting All Vulnerable Packages
38+
-------------------------------
39+
40+
Instead of calling ``/api/packages/all``, call the v3 endpoint with an empty ``purls`` list.
41+
42+
::
43+
44+
POST /api/v3/packages
45+
46+
{
47+
"purls": []
48+
}
49+
50+
Example response:
51+
52+
::
53+
54+
{
55+
"count": 596,
56+
"next": "http://example.com/api/v3/packages?page=2",
57+
"previous": null,
58+
"results": [
59+
"pkg:npm/626@1.1.1",
60+
"pkg:npm/aedes@0.35.0",
61+
"pkg:npm/airbrake@0.3.8",
62+
"pkg:npm/angular-http-server@1.4.3",
63+
"pkg:npm/apex-publish-static-files@2.0.0",
64+
"pkg:npm/atob@2.0.3",
65+
"pkg:npm/augustine@0.2.3",
66+
"pkg:npm/backbone@0.3.3",
67+
"pkg:npm/base64-url@1.3.3",
68+
"pkg:npm/base64url@2.0.0"
69+
]
70+
}
71+
72+
73+
Bulk Search (Replacement)
74+
-------------------------
75+
76+
Instead of calling ``/api/packages/bulk_search``, use:
77+
78+
::
79+
80+
POST /api/v3/packages
81+
82+
Parameters:
83+
84+
- ``purls`` — list of package URLs to query
85+
- ``details`` — boolean (default: ``false``)
86+
- ``ignore_qualifiers_subpath`` — boolean (default: ``false``)
87+
88+
The ``ignore_qualifiers_subpath`` flag replaces the previous ``plain_purl`` parameter.
89+
When set to ``true``, qualifiers and subpaths in PURLs are ignored.
90+
91+
92+
Get Only Vulnerable PURLs
93+
~~~~~~~~~~~~~~~~~~~~~~~~~
94+
95+
::
96+
97+
POST /api/v3/packages
98+
99+
{
100+
"purls": ["pkg:npm/atob@2.0.3", "pkg:pypi/sample@2.0.0"],
101+
"details": false
102+
}
103+
104+
Example response:
105+
106+
::
107+
108+
{
109+
"count": 1,
110+
"next": null,
111+
"previous": null,
112+
"results": [
113+
"pkg:npm/atob@2.0.3"
114+
]
115+
}
116+
117+
118+
Get Detailed Vulnerability Information
119+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120+
121+
::
122+
123+
POST /api/v3/packages
124+
125+
{
126+
"purls": ["pkg:npm/atob@2.0.3", "pkg:pypi/sample@2.0.0"],
127+
"details": true
128+
}
129+
130+
Example response:
131+
132+
::
133+
134+
{
135+
"count": 1,
136+
"next": null,
137+
"previous": null,
138+
"results": [
139+
{
140+
"purl": "pkg:npm/atob@2.0.3",
141+
"affected_by_vulnerabilities": [
142+
{
143+
"advisory_id": "GHSA-g5vw-3h65-2q3v",
144+
"aliases": [],
145+
"weighted_severity": null,
146+
"exploitability_score": null,
147+
"risk_score": null,
148+
"summary": "Access control vulnerable to user data",
149+
"fixed_by_packages": [
150+
"pkg:pypi/accesscontrol@7.2"
151+
],
152+
},
153+
],
154+
"fixing_vulnerabilities": [],
155+
"next_non_vulnerable_version": "2.1.0",
156+
"latest_non_vulnerable_version": "2.1.0",
157+
"risk_score": null
158+
}
159+
]
160+
}
161+
162+
163+
Using Approximate Matching
164+
~~~~~~~~~~~~~~~~~~~~~~~~~~
165+
166+
::
167+
168+
POST /api/v3/packages
169+
170+
{
171+
"purls": ["pkg:npm/atob@2.0.3?foo=bar"],
172+
"ignore_qualifiers_subpath": true,
173+
"details": true
174+
}
175+
176+
Example response:
177+
178+
::
179+
180+
{
181+
"count": 1,
182+
"next": null,
183+
"previous": null,
184+
"results": [
185+
{
186+
"purl": "pkg:npm/atob@2.0.3",
187+
"affected_by_vulnerabilities": [
188+
{
189+
"advisory_id": "GHSA-g5vw-3h65-2q3v",
190+
"aliases": [],
191+
"weighted_severity": null,
192+
"exploitability_score": null,
193+
"risk_score": null,
194+
"summary": "Access control vulnerable to user data",
195+
"fixed_by_packages": [
196+
"pkg:pypi/accesscontrol@7.2"
197+
],
198+
}
199+
],
200+
"fixing_vulnerabilities": [],
201+
"next_non_vulnerable_version": "2.1.0",
202+
"latest_non_vulnerable_version": "2.1.0",
203+
"risk_score": null
204+
}
205+
]
206+
}
207+
208+
209+
Advisory Endpoint
210+
=================
211+
212+
Retrieve advisories for one or more PURLs:
213+
214+
::
215+
216+
POST /api/v3/advisories
217+
218+
{
219+
"purls": ["pkg:npm/atob@2.0.3", "pkg:pypi/sample@2.0.0"]
220+
}
221+
222+
Responses are paginated (10 results per page) and include ``next`` and ``previous`` links.
223+
224+
225+
Affected-By Advisories Endpoint
226+
===============================
227+
228+
Retrieve advisories that **affect (impact)** a given PURL:
229+
230+
::
231+
232+
GET /api/v3/affected-by-advisories?purl=<purl>
233+
234+
Example:
235+
236+
::
237+
238+
GET /api/v3/affected-by-advisories?purl=pkg:npm/atob@2.0.3
239+
240+
241+
Fixing Advisories Endpoint
242+
==========================
243+
244+
Retrieve advisories that are **fixed by** a given PURL:
245+
246+
::
247+
248+
GET /api/v3/fixing-advisories?purl=<purl>
249+
250+
Example:
251+
252+
::
253+
254+
GET /api/v3/fixing-advisories?purl=pkg:npm/atob@2.1.0

0 commit comments

Comments
 (0)