Data Access API
The API provides a powerful and generic endpoint for performing CRUD (Create, Read, Update, Delete) operations on all core data models. This approach simplifies client-side code by providing a consistent interface for data interaction.
- Endpoint:
/api/v1/data
- Authentication: Required (Bearer Token) for all methods.
The model
Query Parameter
Section titled “The model Query Parameter”Every request to this endpoint must include a model
query parameter to specify which data collection you are targeting.
- Example:
GET /api/v1/data?model=headline
Supported Models
Section titled “Supported Models”The following model names are supported:
headline
topic
source
country
(supports specialized filtering byusage
for ‘eventCountry’ or ‘headquarters’)language
user
user_app_settings
user_content_preferences
remote_config
dashboard_summary
Endpoints
Section titled “Endpoints”List Items (Collection)
Section titled “List Items (Collection)”Retrieves a paginated list of items for a specific model.
- Method:
GET
- Path:
/api/v1/data?model=<model_name>
Query Parameters
Section titled “Query Parameters”-
filter
(string, optional): A URL-encoded JSON string representing a MongoDB-style query. -
sort
(string, optional): A comma-separated list of fields to sort by (e.g.,createdAt:desc,title:asc
). -
limit
(integer, optional): The maximum number of items to return. -
cursor
(string, optional): The pagination cursor from a previous response to fetch the next page.
Request:
GET /api/v1/data?model=headline&filter={"status":"active"}
This fetches all headlines where the status
field is "active"
.
Request:
GET /api/v1/data?model=headline&filter={"topic.id":{"$in":["topicId1","topicId2"]}}&sort=createdAt:desc
This fetches headlines belonging to specific topics, sorted by creation date.
Request:
GET /api/v1/data?model=country&filter={"usage":"eventCountry"}
This fetches all countries that are referenced as ‘event countries’ in headlines.
- Success Response:
200 OK
: Returns a standard success response with aPaginatedResponse<T>
object as the data payload.
Create Item
Section titled “Create Item”Creates a new item for a specific model.
-
Method:
POST
-
Path:
/api/v1/data?model=<model_name>
-
Body (JSON): The JSON representation of the model to create. The
id
,createdAt
, andupdatedAt
fields will be automatically generated by the server and should be omitted from the request body. -
Success Response:
201 Created
: Returns a standard success response with the newly created item object as the data payload.
Read Item
Section titled “Read Item”Retrieves a single item by its unique ID.
-
Method:
GET
-
Path:
/api/v1/data/<item_id>?model=<model_name>
-
Success Response:
200 OK
: Returns a standard success response with the requested item object as the data payload.
-
Error Responses:
404 Not Found
: The item with the specified ID does not exist.
Update Item
Section titled “Update Item”Updates an existing item by its unique ID.
- Method:
PUT
- Path:
/api/v1/data/<item_id>?model=<model_name>
- Body (JSON): The full JSON representation of the model with the updated fields.
-
Success Response:
200 OK
: Returns a standard success response with the updated item object as the data payload.
-
Error Responses:
404 Not Found
: The item with the specified ID does not exist.
Delete Item
Section titled “Delete Item”Deletes an item by its unique ID.
-
Method:
DELETE
-
Path:
/api/v1/data/<item_id>?model=<model_name>
-
Success Response:
204 No Content
: The item was successfully deleted.
-
Error Responses:
404 Not Found
: The item with the specified ID does not exist.