2022-01-20 10:40:53 +01:00
|
|
|
export const buildAutomationEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Executes an automation. Must have "App Action" trigger.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @param automationId the ID of the automation to trigger
|
|
|
|
* @param fields the fields to trigger the automation with
|
2022-01-20 10:40:53 +01:00
|
|
|
*/
|
|
|
|
triggerAutomation: async ({ automationId, fields }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/automations/${automationId}/trigger`,
|
|
|
|
body: { fields },
|
|
|
|
})
|
|
|
|
},
|
2022-01-21 16:09:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests an automation with data.
|
|
|
|
* @param automationId the ID of the automation to test
|
|
|
|
* @param testData the test data to run against the automation
|
|
|
|
*/
|
|
|
|
testAutomation: async ({ automationId, testData }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/automations/${automationId}/test`,
|
|
|
|
body: testData,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of all automations.
|
|
|
|
*/
|
|
|
|
getAutomations: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/automations",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of all the definitions for blocks in automations.
|
|
|
|
*/
|
|
|
|
getAutomationDefinitions: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/automations/definitions/list",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an automation.
|
|
|
|
* @param automation the automation to create
|
|
|
|
*/
|
|
|
|
createAutomation: async automation => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/automations",
|
|
|
|
body: automation,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates an automation.
|
|
|
|
* @param automation the automation to update
|
|
|
|
*/
|
|
|
|
updateAutomation: async automation => {
|
|
|
|
return await API.put({
|
|
|
|
url: "/api/automations",
|
|
|
|
body: automation,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes an automation
|
|
|
|
* @param automationId the ID of the automation to delete
|
|
|
|
* @param automationRev the rev of the automation to delete
|
|
|
|
*/
|
|
|
|
deleteAutomation: async ({ automationId, automationRev }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/automations/${automationId}/${automationRev}`,
|
|
|
|
})
|
|
|
|
},
|
2022-06-01 17:01:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the logs for the app, or by automation ID.
|
|
|
|
* @param automationId The ID of the automation to get logs for.
|
|
|
|
* @param startDate An ISO date string to state the start of the date range.
|
2022-06-22 21:23:18 +02:00
|
|
|
* @param status The status, error or success.
|
|
|
|
* @param page The page to retrieve.
|
2022-06-01 17:01:06 +02:00
|
|
|
*/
|
2022-06-01 23:39:51 +02:00
|
|
|
getAutomationLogs: async ({ automationId, startDate, status, page }) => {
|
2022-06-01 17:01:06 +02:00
|
|
|
return await API.post({
|
|
|
|
url: "/api/automations/logs/search",
|
|
|
|
body: {
|
|
|
|
automationId,
|
|
|
|
startDate,
|
2022-06-01 23:39:51 +02:00
|
|
|
status,
|
|
|
|
page,
|
2022-06-01 17:01:06 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-06-22 21:23:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears automation log errors (which are creating notification) for
|
|
|
|
* automation or the app.
|
|
|
|
* @param automationId optional - the ID of the automation to clear errors for.
|
|
|
|
* @param appId The app ID to clear errors for.
|
|
|
|
*/
|
|
|
|
clearAutomationLogErrors: async ({ automationId, appId }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: "/api/automations/logs",
|
|
|
|
body: {
|
|
|
|
appId,
|
|
|
|
automationId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-01-20 10:40:53 +01:00
|
|
|
})
|