Create Audit subscription
This endpoint will create a new Audit Record subscription record in the database. The new record will include the streaming and/or associated configurations. Provide info including where the service should forward the Audit Records, the maximum number of records in each payload, and the frequency for sending them.
URL : http://34.122.70.8/api/v1/audit/subscribe
Method : POST
Auth required : YES
| Headers | Type | Description |
|---|---|---|
| api-key | string | Unique api key provided to each customer |
Permissions required : None
Request Body:
| Field | Type | Description |
|---|---|---|
| endpoint_url | string | Client webhook URL where data is being sent |
| start_time | Date | Date and time from which Audit Records are to be fetched |
| fetch_limit | Number | Max number of Audit Records being sent to client in each message |
| read_interval | Number | Interval, in seconds, between each message to be sent to client |
Request Body example
{
"endpoint_url": "http://localhost:3000/hook",
"start_time": "2022-12-25 12:33:30+05:30",
"fetch_limit": 100,
"read_interval": 60
}
Response Body:
| Field | Type | Description |
|---|---|---|
| status | Boolean | Status of the request |
| msg | string | Response message from server |
| data | Data Object |
Data Object:
| Field | Type | Description |
|---|---|---|
| id | string | Id of the audit subscription table record |
| start_time | Date | Date and time from when Audit Records should be fetched |
| last_read_at | Data Object | Time of the last Audit Record sent via the subscription |
| endpoint_url | string | Client webhook url where data is being sent |
| fetch_limit | string | Max number of Audit records being sent to client in each message |
| read_interval | Number | Interval, in seconds, between messages sent to client |
| status | string | Status of the subscription. For new subscription, the status will be 'active'. |
| createdAt | Date | Date and time subscription was created |
| updatedAt | Data Object | Date and time subscription was last updated |
Response Body example
Success Response
Condition : If everything is OK and the subscription does not already exist.
Code : 201 CREATED
Content example
{
"status": true,
"msg": "Audit record subscribed successfully",
"data": [
{
"id": 1,
"start_time": "2022-12-25T07:03:30.000Z",
"last_read_at": null,
"endpoint_url": "http://localhost:3000/hook",
"fetch_limit": 100,
"read_interval": 60,
"status": "active",
"createdAt": "2023-07-12T17:51:58.439Z",
"updatedAt": "2023-07-12T17:51:58.439Z"
}
]
}
Error Responses
Condition : If the subscription already exist.
Code : 400 Bad Request
Content :
{
"status": false,
"error_code": "ALREADY_EXISTS",
"error_msg": "Subscription already exists. Please unsubscribe first to create a new one"
}
Or
Condition : If endpoint_url field is missing.
Code : 400 BAD REQUEST
Content example
{
"error_code": "BAD_DATA",
"error_msg": "Subscription endpoint url not found or invalid"
}
Or
Condition : If some error was encountered while creating the subscription.
Code : 400 BAD REQUEST
Content example
{
"error_code": "AUDIT_SUBSCRIBE_FAILED",
"error_msg": "Failed to subscribe audit"
}
Or
Condition : If api-key not passed in request header or is wrong.
Code : 401 Unauthorized
Content example
{
"status": false,
"error_code": "AUDIT_UNAUTHORIZED",
"error_msg": "Missing/MisMatch API KEY"
}
- Nodejs
- React
const fetch = require('node-fetch');
let url = 'http://34.122.70.8/api/v1/audit/subscribe';
let options = {
method: 'POST',
headers: {
'api-key': '<API_KEY>',
'Content-Type': 'application/json'
},
body: '{"endpoint_url":"http://localhost:3000/hook","start_time":"2022-12-25 12:33:30+05:30","fetch_limit":100,"read_interval":60}'
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
let headersList = {
"api-key": "<API_KEY>",
"Content-Type": "application/json"
}
let bodyContent = JSON.stringify({
"endpoint_url": "http://localhost:3000/hook",
"start_time": "2022-12-25 12:33:30+05:30",
"fetch_limit": 100,
"read_interval": 60
});
let response = await fetch("http://34.122.70.8/api/v1/audit/subscribe", {
method: "POST",
body: bodyContent,
headers: headersList
});
let data = await response.text();
console.log(data);