Skip to content

Commit 91bf6b0

Browse files
committed
Add "REST API Integration" documentation #345
Signed-off-by: tdruez <[email protected]>
1 parent ff25f10 commit 91bf6b0

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Welcome to the very start of your DejaCode journey!
5353
integrations-gitlab
5454
integrations-jira
5555
integrations-sourcehut
56+
integrations-rest-api
5657

5758
.. toctree::
5859
:maxdepth: 1

docs/integrations-rest-api.rst

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
.. _integrations_rest_api:
2+
3+
REST API Integration
4+
====================
5+
6+
DejaCode offers a REST API to allow integration with external applications in a
7+
generic way. You can use it to fetch, create, and update DejaCode Requests
8+
from your own scripts or applications.
9+
10+
The full REST API documentation is also available in the DejaCode web UI under
11+
**Tools > API Documentation**.
12+
13+
This guide focuses specifically on interacting with **DejaCode Requests**.
14+
15+
.. note::
16+
17+
Example HTTP requests assume the DejaCode URL is ``https://localhost``.
18+
Replace with your actual instance URL.
19+
20+
Prerequisites
21+
-------------
22+
23+
- A **DejaCode API Key**, available from your **Profile** settings page.
24+
25+
Authentication
26+
--------------
27+
28+
Include your **API Key** in the "Authorization" HTTP header for every request.
29+
The key must be prefixed by the string literal ``Token`` followed by a space:
30+
31+
Authorization: Token abcdef123456
32+
33+
.. warning::
34+
Treat your API key like a password — keep it secret and secure.
35+
36+
Example using cURL::
37+
38+
curl -X GET \
39+
https://localhost/api/v2/requests/ \
40+
-H "Authorization: Token abcdef123456"
41+
42+
Example using Python::
43+
44+
import requests
45+
46+
api_url = "https://localhost/api/v2/requests/"
47+
headers = {"Authorization": "Token abcdef123456"}
48+
params = {"page": "2"}
49+
response = requests.get(api_url, headers=headers, params=params)
50+
print(response.json())
51+
52+
Request List
53+
------------
54+
55+
**Endpoint:** ``GET /api/v2/requests/``
56+
57+
This endpoint lists all requests. Responses include pagination fields ``next``
58+
and ``previous`` to navigate through pages.
59+
60+
You can sort the list using ``?ordering=FIELD``. Prefix a field with ``-`` to
61+
reverse the sort order (descending). Available fields:
62+
63+
- ``title``
64+
- ``request_template``
65+
- ``status``
66+
- ``priority``
67+
- ``assignee``
68+
- ``requester``
69+
- ``created_date``
70+
- ``last_modified_date``
71+
72+
Filtering is supported using ``FIELD=VALUE`` syntax. Available filters include:
73+
74+
- ``request_template``
75+
- ``status``
76+
- ``requester``
77+
- ``assignee``
78+
- ``priority``
79+
- ``content_type``
80+
- ``last_modified_date``
81+
82+
Example: Get closed requests sorted by last modification date::
83+
84+
api_url = "https://localhost/api/v2/requests/"
85+
headers = {"Authorization": "Token abcdef123456"}
86+
params = {"status": "closed", "ordering": "last_modified_date"}
87+
response = requests.get(api_url, headers=headers, params=params)
88+
print(response.json())
89+
90+
Request Details
91+
---------------
92+
93+
**Endpoint:** ``GET /api/v2/requests/{uuid}/``
94+
95+
Returns all available information for a specific request. Replace ``{uuid}``
96+
with the UUID of the request you want to retrieve.
97+
98+
Example JSON response snippet::
99+
100+
{
101+
"uuid": "adf1835e-4b58-42d0-b1f4-c57791167d19",
102+
"title": "Issue title",
103+
"request_template": "https://localhost/api/v2/request_templates/5b106292-d8b6-459c-abda-e6a87527a0db/",
104+
"status": "open",
105+
"assignee": "username",
106+
"notes": "",
107+
"serialized_data": {"Notes": "This version has a known vulnerability."},
108+
"created_date": "2025-08-12T17:41:47.424373+04:00",
109+
"last_modified_date": "2025-08-12T17:42:29.031833+04:00",
110+
"comments": [
111+
{
112+
"uuid": "8ee73eb2-353a-4e84-8536-fe4e25a1abf6",
113+
"username": "username",
114+
"text": "Comment content.",
115+
"created_date": "2025-08-14T09:17:55.397285+04:00"
116+
}
117+
]
118+
}
119+
120+
Create a Request
121+
----------------
122+
123+
**Endpoint:** ``POST /api/v2/requests/``
124+
125+
Required fields:
126+
127+
- **title** (string): A short, descriptive title of the request.
128+
- **request_template** (string): URI of the template to use.
129+
- **assignee** (string): Username of the person assigned.
130+
131+
Optional fields:
132+
133+
- **status** (string): ``open``, ``closed``, or ``draft``. Default is ``open``.
134+
- **priority** (string|null): Priority level.
135+
- **product_context** (string|null): URI of a product context.
136+
- **notes** (string): Notes related to the request.
137+
- **serialized_data** (string): Additional structured data.
138+
- **is_private** (boolean): True if only visible to requester/reviewers.
139+
- **content_object** (string|null): URI of associated content object.
140+
- **cc_emails** (array of strings): List of emails to notify.
141+
142+
Example of minimal JSON payload::
143+
144+
{
145+
"title": "New vulnerability found",
146+
"request_template": "Address Vulnerabilities in Product Packages",
147+
"assignee": "username"
148+
}
149+
150+
Example using cURL::
151+
152+
api_url="https://localhost/api/v2/requests/"
153+
headers="Authorization: Token abcdef123456"
154+
data='{
155+
"title": "New vulnerability found",
156+
"request_template": "Address Vulnerabilities in Product Packages",
157+
"assignee": "username"
158+
}'
159+
160+
curl -X POST "$api_url" -H "$headers" -d "$data"
161+
162+
Example using Python::
163+
164+
import requests
165+
api_url = "https://localhost/api/v2/requests/"
166+
headers = {
167+
"Authorization": "Token abcdef123456",
168+
"Content-Type": "application/json"
169+
}
170+
data = {
171+
"title": "New vulnerability found",
172+
"request_template": "Address Vulnerabilities in Product Packages",
173+
"assignee": "username"
174+
}
175+
response = requests.post(api_url, headers=headers, json=data)
176+
print(response.json())
177+
178+
Update a Request
179+
----------------
180+
181+
**Endpoint:** ``PUT /api/v2/requests/{uuid}/``
182+
183+
Performs a full update. All fields of the request must be provided.
184+
185+
Partial Update
186+
--------------
187+
188+
**Endpoint:** ``PATCH /api/v2/requests/{uuid}/``
189+
190+
Allows updating only specific fields. For example, to close a request::
191+
192+
import requests
193+
api_url = "https://localhost/api/v2/requests/{uuid}/"
194+
headers = {
195+
"Authorization": "Token abcdef123456",
196+
"Content-Type": "application/json"
197+
}
198+
data = {"status": "closed"}
199+
response = requests.patch(api_url, headers=headers, json=data)
200+
print(response.json())
201+

0 commit comments

Comments
 (0)