Automation API Reference
The Automation API allows you to programmatically create and manage automated triggers and actions.
Information
API Overview
The Automation API provides endpoints for creating, retrieving, updating, and deleting automations. Automations consist of triggers (conditions that initiate the automation) and actions (operations to perform when triggered).
Base URL
1https://api.neoservicelayer.com/v1/automations
Endpoints
List Automations
Retrieves a list of automations in your account.
GET /automations
Query Parameters
status
(optional) - Filter by status: "active", "inactive", "error"triggerType
(optional) - Filter by trigger type: "schedule", "blockchain", "price"limit
(optional) - Number of items to return (default: 20, max: 100)offset
(optional) - Pagination offset (default: 0)
Example Request
1curl -X GET "https://api.neoservicelayer.com/v1/automations?status=active" \
2 -H "Authorization: Bearer YOUR_API_KEY"
Response
1{
2 "automations": [
3 {
4 "id": "auto_123456789",
5 "name": "Daily Update",
6 "status": "active",
7 "trigger": {
8 "type": "schedule",
9 "cron": "0 0 * * *"
10 },
11 "action": {
12 "type": "function",
13 "functionId": "func_abcdef123",
14 "parameters": {
15 "operation": "daily-update"
16 }
17 },
18 "createdAt": "2023-03-15T10:30:45Z",
19 "updatedAt": "2023-03-15T10:30:45Z"
20 },
21 {
22 "id": "auto_987654321",
23 "name": "Price Alert",
24 "status": "active",
25 "trigger": {
26 "type": "price",
27 "asset": "NEO",
28 "condition": "above",
29 "value": "50.00",
30 "currency": "USD"
31 },
32 "action": {
33 "type": "function",
34 "functionId": "func_xyz789",
35 "parameters": {
36 "notify": true
37 }
38 },
39 "createdAt": "2023-03-10T15:20:30Z",
40 "updatedAt": "2023-03-10T15:20:30Z"
41 }
42 ],
43 "pagination": {
44 "total": 2,
45 "limit": 20,
46 "offset": 0
47 }
48}
Create Automation
Creates a new automation in your account.
POST /automations
Request Body
1{
2 "name": "Daily Update",
3 "trigger": {
4 "type": "schedule",
5 "cron": "0 0 * * *"
6 },
7 "action": {
8 "type": "function",
9 "functionId": "func_abcdef123",
10 "parameters": {
11 "operation": "daily-update"
12 }
13 },
14 "status": "active"
15}
Example Request
1curl -X POST "https://api.neoservicelayer.com/v1/automations" \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "name": "Daily Update",
6 "trigger": {
7 "type": "schedule",
8 "cron": "0 0 * * *"
9 },
10 "action": {
11 "type": "function",
12 "functionId": "func_abcdef123",
13 "parameters": {
14 "operation": "daily-update"
15 }
16 },
17 "status": "active"
18 }'
Response
1{
2 "id": "auto_123456789",
3 "name": "Daily Update",
4 "status": "active",
5 "trigger": {
6 "type": "schedule",
7 "cron": "0 0 * * *"
8 },
9 "action": {
10 "type": "function",
11 "functionId": "func_abcdef123",
12 "parameters": {
13 "operation": "daily-update"
14 }
15 },
16 "createdAt": "2023-03-15T10:30:45Z",
17 "updatedAt": "2023-03-15T10:30:45Z"
18}
Get Automation
Retrieves information about a specific automation.
GET /automations/{automationId}
Path Parameters
automationId
(required) - The ID of the automation to retrieve
Example Request
1curl -X GET "https://api.neoservicelayer.com/v1/automations/auto_123456789" \
2 -H "Authorization: Bearer YOUR_API_KEY"
Response
1{
2 "id": "auto_123456789",
3 "name": "Daily Update",
4 "status": "active",
5 "trigger": {
6 "type": "schedule",
7 "cron": "0 0 * * *"
8 },
9 "action": {
10 "type": "function",
11 "functionId": "func_abcdef123",
12 "parameters": {
13 "operation": "daily-update"
14 }
15 },
16 "executionStats": {
17 "lastExecution": "2023-03-15T00:00:00Z",
18 "lastStatus": "success",
19 "successCount": 15,
20 "failureCount": 0,
21 "nextExecution": "2023-03-16T00:00:00Z"
22 },
23 "createdAt": "2023-03-01T10:30:45Z",
24 "updatedAt": "2023-03-15T10:30:45Z"
25}
Supported Trigger Types
Schedule Trigger
Executes an action based on a schedule defined using cron syntax.
1{
2 "type": "schedule",
3 "cron": "0 0 * * *" // Daily at midnight
4}
Blockchain Trigger
Executes an action in response to blockchain events, such as contract notifications.
1{
2 "type": "blockchain",
3 "scriptHash": "0x1234567890abcdef1234567890abcdef12345678",
4 "event": "Transfer", // Optional: Filter by specific event
5 "filter": { // Optional: Filter by event parameters
6 "from": "NXV6HUtNX3bkWFw2ESjkQZj8b5AV2CRnrP"
7 }
8}
Price Trigger
Executes an action when an asset's price meets a specific condition.
1{
2 "type": "price",
3 "asset": "NEO",
4 "condition": "above", // "above" or "below"
5 "value": "50.00",
6 "currency": "USD"
7}
Supported Action Types
Function Action
Executes a deployed Function with the specified parameters.
1{
2 "type": "function",
3 "functionId": "func_abcdef123",
4 "parameters": {
5 // Any parameters to pass to the function
6 "operation": "daily-update"
7 }
8}
Contract Action
Invokes a smart contract method on the Neo N3 blockchain.
1{
2 "type": "contract",
3 "scriptHash": "0x1234567890abcdef1234567890abcdef12345678",
4 "operation": "transfer",
5 "args": [
6 {
7 "type": "Hash160",
8 "value": "NXV6HUtNX3bkWFw2ESjkQZj8b5AV2CRnrP"
9 },
10 {
11 "type": "Integer",
12 "value": "100000000" // 1 GAS in smallest units
13 }
14 ]
15}
Error Codes
Status Code | Error Code | Description |
---|---|---|
400 | INVALID_REQUEST | The request was invalid or missing required parameters |
400 | INVALID_CRON | The provided cron expression is invalid |
400 | INVALID_SCRIPT_HASH | The provided script hash is invalid |
404 | FUNCTION_NOT_FOUND | The specified function does not exist |
404 | AUTOMATION_NOT_FOUND | The specified automation does not exist |
Further Learning
For more information on creating and using automations, see the Setting Up Automation Guide.