|
1 | 1 | # Cloud API Layer |
2 | 2 |
|
3 | | -Direct REST access to the Redis Cloud API. |
| 3 | +Direct REST access to the Redis Cloud API for scripting and automation. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
7 | | -The API layer provides raw access to all Redis Cloud REST endpoints. Use this for: |
8 | | -- Scripting and automation |
9 | | -- Accessing endpoints not yet wrapped in human commands |
10 | | -- CI/CD pipelines |
| 7 | +The API layer lets you call any Redis Cloud REST endpoint directly. It's like a smart curl with: |
| 8 | +- Automatic authentication |
| 9 | +- Profile support |
| 10 | +- Output formatting |
11 | 11 |
|
12 | | -## Authentication |
| 12 | +## Usage |
13 | 13 |
|
14 | | -Uses `x-api-key` and `x-api-secret-key` headers. Configure via profile or environment variables. |
| 14 | +```bash |
| 15 | +redisctl api cloud <method> <endpoint> [options] |
| 16 | +``` |
15 | 17 |
|
16 | | -## Usage |
| 18 | +**Methods:** `get`, `post`, `put`, `delete` |
| 19 | + |
| 20 | +## Examples |
| 21 | + |
| 22 | +### GET Requests |
17 | 23 |
|
18 | 24 | ```bash |
19 | | -# GET request |
| 25 | +# Account info |
| 26 | +redisctl api cloud get / |
| 27 | + |
| 28 | +# List subscriptions |
20 | 29 | redisctl api cloud get /subscriptions |
21 | 30 |
|
22 | | -# POST request with data |
23 | | -redisctl api cloud post /subscriptions -d '{"name": "test", ...}' |
| 31 | +# Get specific subscription |
| 32 | +redisctl api cloud get /subscriptions/123456 |
24 | 33 |
|
25 | | -# PUT request |
26 | | -redisctl api cloud put /subscriptions/123 -d '{"name": "updated"}' |
| 34 | +# List databases |
| 35 | +redisctl api cloud get /subscriptions/123456/databases |
27 | 36 |
|
28 | | -# DELETE request |
29 | | -redisctl api cloud delete /subscriptions/123/databases/456 |
| 37 | +# Get specific database |
| 38 | +redisctl api cloud get /subscriptions/123456/databases/789 |
30 | 39 | ``` |
31 | 40 |
|
| 41 | +### POST Requests |
| 42 | + |
| 43 | +```bash |
| 44 | +# Create subscription |
| 45 | +redisctl api cloud post /subscriptions -d @subscription.json |
| 46 | + |
| 47 | +# Create database |
| 48 | +redisctl api cloud post /subscriptions/123456/databases -d '{ |
| 49 | + "name": "mydb", |
| 50 | + "memoryLimitInGb": 1 |
| 51 | +}' |
| 52 | +``` |
| 53 | + |
| 54 | +### PUT Requests |
| 55 | + |
| 56 | +```bash |
| 57 | +# Update database |
| 58 | +redisctl api cloud put /subscriptions/123456/databases/789 -d '{ |
| 59 | + "memoryLimitInGb": 2 |
| 60 | +}' |
| 61 | +``` |
| 62 | + |
| 63 | +### DELETE Requests |
| 64 | + |
| 65 | +```bash |
| 66 | +# Delete database |
| 67 | +redisctl api cloud delete /subscriptions/123456/databases/789 |
| 68 | + |
| 69 | +# Delete subscription |
| 70 | +redisctl api cloud delete /subscriptions/123456 |
| 71 | +``` |
| 72 | + |
| 73 | +## Options |
| 74 | + |
| 75 | +| Option | Description | |
| 76 | +|--------|-------------| |
| 77 | +| `-d, --data <JSON>` | Request body (inline or @file) | |
| 78 | +| `-o, --output <FORMAT>` | Output format (json, yaml, table) | |
| 79 | +| `-q, --query <JMESPATH>` | Filter output | |
| 80 | + |
32 | 81 | ## Common Endpoints |
33 | 82 |
|
34 | | -- `/account` - Account information |
35 | | -- `/subscriptions` - Subscription management |
36 | | -- `/subscriptions/{id}/databases` - Database operations |
37 | | -- `/acl/users` - User management |
38 | | -- `/acl/roles` - Role management |
39 | | -- `/tasks` - Async task status |
| 83 | +### Account |
| 84 | +- `GET /` - Account info |
| 85 | +- `GET /payment-methods` - Payment methods |
| 86 | +- `GET /regions` - Available regions |
| 87 | + |
| 88 | +### Subscriptions |
| 89 | +- `GET /subscriptions` - List all |
| 90 | +- `POST /subscriptions` - Create |
| 91 | +- `GET /subscriptions/{id}` - Get one |
| 92 | +- `PUT /subscriptions/{id}` - Update |
| 93 | +- `DELETE /subscriptions/{id}` - Delete |
| 94 | + |
| 95 | +### Databases |
| 96 | +- `GET /subscriptions/{id}/databases` - List |
| 97 | +- `POST /subscriptions/{id}/databases` - Create |
| 98 | +- `GET /subscriptions/{id}/databases/{dbId}` - Get |
| 99 | +- `PUT /subscriptions/{id}/databases/{dbId}` - Update |
| 100 | +- `DELETE /subscriptions/{id}/databases/{dbId}` - Delete |
| 101 | + |
| 102 | +### ACL |
| 103 | +- `GET /acl/users` - List users |
| 104 | +- `GET /acl/roles` - List roles |
| 105 | +- `GET /acl/redisRules` - List Redis rules |
| 106 | + |
| 107 | +### Networking |
| 108 | +- `GET /subscriptions/{id}/peerings` - VPC peerings |
| 109 | +- `GET /subscriptions/{id}/privateServiceConnect` - PSC |
| 110 | +- `GET /subscriptions/{id}/transitGateway` - Transit Gateway |
| 111 | + |
| 112 | +### Tasks |
| 113 | +- `GET /tasks` - List tasks |
| 114 | +- `GET /tasks/{taskId}` - Get task |
| 115 | + |
| 116 | +## Scripting Examples |
| 117 | + |
| 118 | +### Create and Wait |
| 119 | + |
| 120 | +```bash |
| 121 | +# Create database |
| 122 | +TASK_ID=$(redisctl api cloud post /subscriptions/123/databases \ |
| 123 | + -d @database.json \ |
| 124 | + -q 'taskId') |
| 125 | + |
| 126 | +# Poll for completion |
| 127 | +while true; do |
| 128 | + STATUS=$(redisctl api cloud get /tasks/$TASK_ID -q 'status') |
| 129 | + [ "$STATUS" = "processing-completed" ] && break |
| 130 | + [ "$STATUS" = "processing-error" ] && exit 1 |
| 131 | + sleep 10 |
| 132 | +done |
| 133 | + |
| 134 | +# Get result |
| 135 | +redisctl api cloud get /tasks/$TASK_ID -q 'response.resourceId' |
| 136 | +``` |
| 137 | + |
| 138 | +### Bulk Operations |
| 139 | + |
| 140 | +```bash |
| 141 | +# Get all database IDs |
| 142 | +DBS=$(redisctl api cloud get /subscriptions/123/databases -q '[].databaseId') |
| 143 | + |
| 144 | +# Process each |
| 145 | +for db in $(echo $DBS | jq -r '.[]'); do |
| 146 | + redisctl api cloud get /subscriptions/123/databases/$db |
| 147 | +done |
| 148 | +``` |
| 149 | + |
| 150 | +### Export to File |
| 151 | + |
| 152 | +```bash |
| 153 | +# Save subscription config |
| 154 | +redisctl api cloud get /subscriptions/123 > subscription.json |
| 155 | + |
| 156 | +# Save all databases |
| 157 | +redisctl api cloud get /subscriptions/123/databases > databases.json |
| 158 | +``` |
| 159 | + |
| 160 | +## When to Use API Layer |
| 161 | + |
| 162 | +**Use API layer when:** |
| 163 | +- Endpoint isn't wrapped in human commands yet |
| 164 | +- You need exact control over the request |
| 165 | +- Building automation scripts |
| 166 | +- Exploring the API |
| 167 | + |
| 168 | +**Use human commands when:** |
| 169 | +- There's a command for what you need |
| 170 | +- You want built-in `--wait` support |
| 171 | +- You prefer ergonomic flags over JSON |
| 172 | + |
| 173 | +## API Documentation |
40 | 174 |
|
41 | | -TODO: Move detailed content from common-features/raw-api.md |
| 175 | +Full API documentation: [Redis Cloud API Docs](https://api.redislabs.com/v1/swagger-ui.html) |
0 commit comments